﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.WebSockets;
using System.Windows.Media.Media3D;

namespace TestDxfDocument

{

    class cuttap
    {
        public static void Cuttap1(Dictionary<string, Object> data)//切削丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double dim = 1;
            double scale = 5;
            /*double tcl = 4 * scale;
            double td = 4 * scale;
            double thl = 16 * scale;
            double oal = 40 * scale;
            double dmm = 3.8 * scale;
            double dn;
            double drvl;
            double lu;
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = dmm - dmm / 10.0;
            }
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.25 * (oal / 40.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = 4 * scale;
            double p = 1*scale ;//螺距
            double h = 0.866025*scale ;//根据螺纹牙型标准中的p得知h牙高的值
            double k = 8.30;//螺纹头部断开角度
            double k_ = k * pi / 180;
            double an = 0;
            double an_ = an * pi / 180;
            double l5 = 4;
            double ap = 0;
            double γp = 5;
            double ap_ = ap * pi / 180;


            double fha = 85;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;
            */
            double tcl = Convert.ToDouble(data["tcl"]);
            double td = Convert.ToDouble(data["td"]);
            double thl = Convert.ToDouble(data["thl"]);
            double oal = Convert.ToDouble(data["oal"]);
            double dmm = Convert.ToDouble(data["dconms"]);
            double dn;
            double drvl;
            double lu;

           
            try
            {
                drvl = Convert.ToDouble(data["drvl"]);
            }
            catch
            {
                drvl = 3.25 * (oal / 40.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]);
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = Convert.ToDouble(data["drvsc"]);
            double p = Convert.ToDouble(data["tp"]);//螺距
            double h = Convert.ToDouble(data["h"]);//根据螺纹牙型标准中的p得知h牙高的值
            try
            {
                dn = Convert.ToDouble(data["dn"]);
            }
            catch
            {
                dn = td - h * 2;
            }
            double k = Convert.ToDouble(data["k"]);//螺纹头部断开角度
            double k_ = k * pi / 180;
            double an = Convert.ToDouble(data["an"]);
            double an_ = an * pi / 180;
            double l5 = tcl;
            double ap = Convert.ToDouble(data["ap"]);
            double γp = Convert.ToDouble(data["rp"]);
            double ap_ = ap * pi / 180;


            double fha = 85;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, 0, oal+5);
            Vector2 p0_2 = fun.Polar(p0, pi, 5);
            Vector2 p1_1 = fun.Polar(p0, pi / 2, td / 2.0 - h);
            Vector2 p1_2 = fun.Polar(p1_1, k_, (tcl * p)/Math.Cos(k_));
            Vector2 p1_3 = fun.Polar(p0, pi / -2, td / 2.0 - h);
            Vector2 p1_4 = fun.Polar(p1_3, -k_, (tcl * p) / Math.Cos(k_));
            //虚拟矩阵，不显示
            Vector2 p1 = fun.Polar(p0, pi / 2, td / 2.0);
            Vector2 p2 = fun.Polar(p1, 0, thl);
            Vector2 p3 = fun.Polar(p2, pi / -2, td / 2.0);
            Vector2 p4 = fun.Polar(p0, pi / -2, td / 2.0);
            //螺纹
            Vector2 p7 = p0;
            Vector2 p5 = p0;
            Vector2 p6 = p0 ;
            Vector2 p8 = p0;
            Vector2 p9 = p0;
            Vector2 p10 = p0;
            Vector2 p11 = p0;
            Vector2 p12 = p0;
            Vector2 p13 = p0;
            Vector2 p14 = p0;
            Vector2 p15 = p0;
            Vector2 p16 = p0;
            Vector2 p17 = p0;
            Vector2 p18 = p1_1;
            Vector2 p19 = p0;
            Vector2 p20 = p0;
            Vector2 p21 = p0;
            var polyline1 = Pus.AddPointsToLwPolyLine(p0);
            var polyline1_1 = Pus.AddPointsToLwPolyLine(p0);
            var polyline2 = Pus.AddPointsToLwPolyLine(p0);
            for (int i = 0; i < l5; i++)
            {
                if ( i==0)
                {
                     p5 = fun.Polar(p7, pi / 2, td / 2 - h);
                    p10 = new Vector2(p5.X + (td / 2 - h) / Math.Tan(fha_), -p5.Y);
                }
                else
                {
                     p5 = p7;
                    p10 = p13;
                }
                p6 = new Vector2 (p5.X +p/2.0,p5.Y +h);
                p7 = new Vector2(p6.X + (p6.X - p5.X), p5.Y);
                p8 = fun.Inters(p5, p6, p1_1, p1_2);
                Vector2 p8_1 = fun.Polar(p8, pi / 2, h);
                p9 = fun.Inters(p6, p7, p1_1, p1_2);
                Vector2 p9_1 = fun.Polar(p9, pi / 2, h);
                p11=new Vector2 (p8.X + (td / 2 - h) / Math.Tan(fha_), -p8.Y);
                p12=new Vector2(p9.X + (td / 2 - h) / Math.Tan(fha_), -p9.Y);
                p13=new Vector2(p7.X + (td / 2 - h) / Math.Tan(fha_), -p7.Y);
                p14 = fun.Inters(p5, p10, p0_1, p0_2);
                p15 = fun.Inters(p8, p11, p0_1, p0_2);
                p16 = fun.Inters(p9, p12, p0_1, p0_2);
                p17 = fun.Inters(p7, p13, p0_1, p0_2);
                p19 = fun.Polar(p18, pi / -2, td - 2 * h);
                p20 = fun.Polar(p19, 0, (td / 2 - h) / Math.Tan(fha_));
                polyline1 = Pus.AddPointsToLwPolyLine(p5, p8, p9, p7);
                polyline1_1 = Pus.AddPointsToLwPolyLine( p8,p8_1,p8,p9,p9_1,p9);
                polyline2 = Pus.AddPointsToLwPolyLine(p14, p10, p11, p15, p11, p12, p16, p12, p13, p17, p13);
                var polyline3 = Pus.AddPointsToLwPolyLine(p18, p19, p20);

                p21 = fun.Polar(p0, pi / 2, h);
                Vector2 p21_3 = fun.Polar(p0, 0, (td / 2 - h) / Math.Tan(fha_));
                var polyline4 = Pus.OffsetLwPolyline(polyline1, p21);
                var polyline4_1 = Pus.MirrorPolyline(polyline4, p0_1, p0_2);
                var polyline4_2 = Pus.OffsetLwPolyline(polyline4_1, p21_3);
                //dxf.AddEntity(new EntityObject[] { polyline1, polyline1_1, polyline2, polyline3, polyline4, polyline4_2 });
                fun.PolyFill(dxf, polyline1, 0.07, contour);
                fun.PolyFill(dxf, polyline1_1, 0.1, contour);
                fun.PolyFill(dxf, polyline2, 0.07, contour);
                fun.PolyFill(dxf, polyline3, 0.1, contour);
                fun.PolyFill(dxf, polyline4, 0.1, contour);
                fun.PolyFill(dxf, polyline4_2, 0.1, contour);
            }
            double a1 = (thl - p * l5)/(p);
             int a2 = (int)a1;
            for (int j = 0; j < a2; j++)
            {
                p5 = p7;
                p6 = new Vector2(p5.X +p / 2.0, p5.Y + h);
                Vector2 p6_1 = fun.Polar(p6, pi / 2, h);
                p7 = new Vector2(p6.X + (p6.X - p5.X), p5.Y);
                p8= new Vector2(p5.X + (td / 2 - h) / Math.Tan(fha_), -p5.Y);
                p9= new Vector2(p6.X + (td / 2 - h) / Math.Tan(fha_), -p6.Y);
                p10= new Vector2(p7.X + (td / 2 - h) / Math.Tan(fha_), -p7.Y);
                p14 = fun.Inters(p8, p5, p0_1, p0_2);
                p15 = fun.Inters(p9, p6, p0_1, p0_2);
                p16 = fun.Inters(p10, p7, p0_1, p0_2);
                polyline2 = Pus.AddPointsToLwPolyLine(p14, p8, p9, p15, p9, p10, p16, p10);
                polyline1 = Pus.AddPointsToLwPolyLine(p5, p6, p7);
                polyline1_1 = Pus.AddPointsToLwPolyLine(p6, p6_1);
                p21 = new Vector2(0,h );
                Vector2 p21_1 = fun.Polar(p0, 0, (td / 2 - h) / Math.Tan(fha_));
                var polyline4 = Pus.OffsetLwPolyline(polyline1, p21);
                var polyline4_1 = Pus.MirrorPolyline(polyline4, p0_1, p0_2);
                var polyline4_2 = Pus.OffsetLwPolyline(polyline4_1, p21_1);
                //dxf.AddEntity(new EntityObject[] { polyline1,polyline1_1, polyline2,polyline4 , polyline4_2 });
                fun.PolyFill(dxf, polyline1, 0.07, contour);
                fun.PolyFill(dxf, polyline1_1, 0.1, contour);
                fun.PolyFill(dxf, polyline2, 0.07, contour);
                fun.PolyFill(dxf, polyline4, 0.1, contour);
                fun.PolyFill(dxf, polyline4_2, 0.1, contour);
            }
            Vector2 p22 = fun.Polar(p0, pi / -2, td / 2.0);
            Vector2 p23 = fun.Polar(p22, 0, (td / 2 - h) / Math.Tan(fha_));
            var polyline5 = Pus.AddPointsToLwPolyLine(p0, p22, p23);
            //dxf.AddEntity(new EntityObject[] { polyline5 });
            fun.PolyFill(dxf, polyline5, 0.1, contour);
            //柄部
            Vector2 p25 = fun.Polar(p7, pi / 2, h);
            Vector2 p25_1 = new Vector2(p25.X, dn / 2.0);
            Vector2 p26 = fun.Polar(p25, pi / -2, td);
            Vector2 p27 = fun.Polar(p26, 0, (td / 2 - h) / Math.Tan(fha_));
            Vector2 p27_1 = new Vector2(p27.X, -dn / 2.0);
            Vector2 p28_1 = fun.Polar(p7, pi / -2, td - 2 * h);
            Vector2 p28 = fun.Polar(p28_1, 0, (td / 2 - h) / Math.Tan(fha_));
            Vector2 p29 = fun.Polar(p25_1, 0, lu-thl );
            Vector2 p30 = new Vector2(p29.X, dmm / 2.0);
            Vector2 p31 = fun.mirrorpoint(p29, p0_1, p0_2);
            Vector2 p32 = fun.mirrorpoint(p30, p0_1, p0_2);
            Vector2 p33 = fun.Polar(p30, 0, oal - lu);
            Vector2 p34 = fun.mirrorpoint(p33, p0_1, p0_2);
            Vector2 p35_1 = fun.Polar(p33, pi / -2, dmm/2.0 - dmm / 2.0 / 10.0);
            Vector2 p35 = fun.Polar(p35_1, pi, 0.42 * (oal / 40.0));
            Vector2 p36 = fun.Polar(p33, pi, drvl );
            Vector2 p37 = new Vector2(p36.X, p35.Y);
            Vector2 p38 = fun.mirrorpoint(p35, p0_1, p0_2);
            Vector2 p39 = fun.mirrorpoint(p36, p0_1, p0_2);
            Vector2 p40 = fun.mirrorpoint(p37, p0_1, p0_2);
            Vector2 p41 = new Vector2(p35.X, p36.Y);
            Vector2 p42 = new Vector2(p38.X, p39.Y);
            var polyline6 = Pus.AddPointsToLwPolyLine(p25, p28, p27,p27_1, p31, p32,p42,p40,p38,p35,p36, p41, p30, p32, p29, p25_1);
            var polyline7 = Pus.AddPointsToLwPolyLine( p42, p40, p38, p39, p42, p39, p40, p38, p35, p36, p41, p37, p35,p37, p36, p41);
            Line line1 = new Line(p33, p34);
            Arc arc1 = fun.DrawArc5(p35, line1, p41);
            Arc arc2 = fun.DrawArc5(p42, line1, p38);
            //dxf.AddEntity(new EntityObject[] { polyline6, polyline7, arc1, arc2 });
            fun.PolyFill(dxf, polyline6, 0.1, contour);
            fun.PolyFill(dxf, polyline7, 0.1, contour);
            fun.drawBArc(dxf, arc1, 0.1, contour);
            fun.drawBArc(dxf, arc2, 0.1, contour);
            //颈部
            Vector2 p43 = fun.Polar(p7, pi / -2, oal);
            Vector2 p44 = fun.Inters(p0_1, p0_2, p7, p43);
            Vector2 p45 = fun.Polar(p44, 0, (lu - thl) * (1.75 / 9.95));
            Vector2 p46 = fun.Polar(p7, 0, (lu - thl) * (1.75 / 9.95));
            Vector2 p47 = fun.Polar(p28, 0, (lu - thl) * (3.5 / 9.95));
            p47 = fun.Polar(p28, 0, p45.X - p44.X);
            Vector2 p45_1 = fun.Polar(fun.Polar(p45, 0, (lu - (thl)) * (4.5 / 50.0)), pi / 2, fun.CalDistance(p45, p46) / 2.0);
            Vector2 p48_1 = fun.Polar(p45_1, pi / -2, oal);
            Vector2 p48 = fun.Inters(fun .Polar (p27,pi/2,(dmm-dn)/2.0), fun.Polar(p31, pi / 2, (dmm - dn) / 2.0), p45_1, p48_1);
            var polyline13 = Pus.AddPointsToLwPolyLine(p44, p45, p45_1, p46, p7);
            polyline13.Vertexes[1].Bulge = Math.Tan((60 * pi / 180) / 4);
            polyline13.Vertexes[2].Bulge = Math.Tan((60 * pi / 180) / 4);
            //dxf.AddEntity(polyline13);
            var polyline14 = Pus.AddPointsToLwPolyLine(p28, p47,p48);
            polyline14.Vertexes[1].Bulge = -Math.Tan((60 * pi / 180) / 4);
            //dxf.AddEntity(polyline14);
            fun.PolyFill(dxf, polyline13, 0.1, contour);
            fun.PolyFill(dxf, polyline14, 0.1, contour);
            //侧面
            try
            {
                drvsc = Convert.ToDouble(data["drvsc"]);
                
            }
            catch
            {
                drvsc = td;
            }
            Vector2 p50=p0 ;
            Vector2 p51=p0 ;
                Vector2 p49_1 = fun.Polar(p0, pi, oal / 1.5);
            Vector2 p49 = fun.Polar(p0 , 0,oal+ oal / 3.0);
                p50 = fun.Polar(p49, pi / 2, drvsc / 2.0);
                Vector2 p50_1 = fun.Polar(p50, pi + pi / 4, drvsc / 10.0);
                Vector2 p50_2 = fun.Polar(p50, pi / -4, drvsc / 10.0);
                p51 = fun.Polar(p49, 0, drvsc / 2.0);
                Vector2 p51_1 = fun.Polar(p51, pi - pi / 4, drvsc / 10.0);
                Vector2 p51_2 = fun.Polar(p51, pi + pi / 4, drvsc / 10.0);
                Vector2 p52 = fun.Polar(p49, pi / -2, drvsc / 2.0);
                Vector2 p52_1 = fun.Polar(p52, pi / 4, drvsc / 10.0);
                Vector2 p52_2 = fun.Polar(p52, pi - pi / 4, drvsc / 10.0);
                Vector2 p53 = fun.Polar(p49, pi, drvsc / 2.0);
                Vector2 p53_1 = fun.Polar(p53, pi / -4, drvsc / 10.0);
                Vector2 p53_2 = fun.Polar(p53, pi / 4, drvsc / 10.0);
                var polyline9 = Pus.AddPointsToLwPolyLine(p50_1, p50_2, p51_1, p51_2, p52_1, p52_2, p53_1, p53_2, p50_1);
                polyline9.Vertexes[0].Bulge = -Math.Tan((90 * pi / 180) / 4);
                polyline9.Vertexes[2].Bulge = -Math.Tan((90 * pi / 180) / 4);
                polyline9.Vertexes[4].Bulge = -Math.Tan((90 * pi / 180) / 4);
                polyline9.Vertexes[6].Bulge = -Math.Tan((90 * pi / 180) / 4);
                fun.PolyFill(dxf, polyline9, 0.1, contour);
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = polyline9.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = polyline9.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)polyline9.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)polyline9.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 3 * (oal / 40.0), hline1, harc1, hatching);
            //左视
            Circle circle1 = new Circle(p49_1, dmm / 2.0);
            Circle circle2 = new Circle(p49_1, td / 2.0);//外轮廓参照
            Arc arc2_1 = fun.DrawArc4(fun.Polar(p49_1, 0, td / 2.0), circle2.Radius, fun.Polar(p49_1, 179.99 * pi / 180, td / 2.0),0);
            Vector2 p54 = fun.Polar(p49_1, pi / 2, td / 2.0+2*h);
            Vector2 p54_1 = fun.Polar(fun.PointRotate(p54, p49_1, ap_), pi / -4, dmm * (1 / 19.0));
            Vector2 p55 = fun.Polar(p49_1, pi / 6, td / 2.0+2*h);
            Vector2 p56 = fun.Polar(p49_1, pi / 2, td /2.0- td / 15.0+2*h);
            Vector2 p57 = fun.Polar(p49_1, pi / 6, td /2.0- td / 15.0+2*h);
            Circle circle3 = new Circle(p54_1, dmm / 2.0);
            circle3.Linetype = Linetype.Dashed;
            circle3.Lineweight = Lineweight.W35;
            circle3.Layer = centre;
            dxf.AddEntity(circle3);
            for (int j = 0; j < 3; j++)
            {
                Arc arc5 = fun.DrawArc(p55, p49_1, p54);
                Vector2 arc5_1 = fun.PointRotate(Pus.ToV2(arc5.Center), fun.Polar(Pus.ToV2(arc5.Center), arc5.StartAngle*pi/180, arc5.Radius), 120 * j * pi / 180);
                Vector2 arc5_2 = fun.PointRotate(Pus.ToV2(arc5.Center), fun.Polar(Pus.ToV2(arc5.Center), arc5.EndAngle*pi/180, arc5.Radius), 120 *j * pi / 180);
                arc5 = fun.DrawArc(arc5_1, Pus.ToV2(arc5.Center), arc5_2);
                Arc arc7 = fun.DrawArc(p57, p49_1, p56);
                Vector2 arc7_1 = fun.PointRotate(Pus.ToV2(arc7.Center), fun.Polar(Pus.ToV2(arc7.Center), arc7.StartAngle*pi/180, arc7.Radius), 120 * j * pi / 180);
                Vector2 arc7_2 = fun.PointRotate(Pus.ToV2(arc7.Center), fun.Polar(Pus.ToV2(arc7.Center), arc7.EndAngle*pi/180, arc7.Radius), 120 * j * pi / 180);
                arc7 = fun.DrawArc(arc7_1, Pus.ToV2(arc7.Center), arc7_2);
                Arc arc6 = fun.Rotatingcircle(arc5, p54, ap_);
                Vector2 arc6_1 = fun.PointRotate(Pus.ToV2(arc6.Center), fun.Polar(Pus.ToV2(arc6.Center), arc6.StartAngle * pi / 180, arc6.Radius), 120 * j * pi / 180);
                Vector2 arc6_2 = fun.PointRotate(Pus.ToV2(arc6.Center), fun.Polar(Pus.ToV2(arc6.Center), arc6.EndAngle * pi / 180, arc6.Radius), -120 * j * pi / 180);
                arc6 = fun.DrawArc(arc6_1, Pus.ToV2(arc6.Center), arc6_2);
                Arc arc8 = fun.Rotatingcircle(arc7, p56, ap_);
                Vector2 arc8_1 = fun.PointRotate(Pus.ToV2(arc8.Center), fun.Polar(Pus.ToV2(arc8.Center), arc8.StartAngle*pi/180, arc8.Radius), 120 * j * pi / 180);
                Vector2 arc8_2 = fun.PointRotate(Pus.ToV2(arc8.Center), fun.Polar(Pus.ToV2(arc8.Center), arc8.EndAngle*pi/180, arc8.Radius), -120 * j * pi / 180);
                arc8 = fun.DrawArc(arc8_1, Pus.ToV2(arc8.Center), arc8_2);
                if (ap == 0)
                {
                    Vector2 p58 = fun.Polar(Pus.ToV2(arc5.Center), (arc5.StartAngle) * pi / 180 - pi / 3.0, arc5.Radius);
                    Vector2 p59 = fun.Polar(Pus.ToV2(arc7.Center), (arc7.StartAngle) * pi / 180 - pi / 3.0, arc7.Radius);
                    Arc arc9 = fun.DrawArc3(fun.Polar(Pus.ToV2(arc5.Center), (arc5.StartAngle) * pi / 180, arc5.Radius), p59, p58);
                    //dxf.AddEntity(new EntityObject[] { arc5, arc7, arc9 });
                    fun.drawBArc(dxf, arc5, 0.1, contour);
                    fun.drawBArc(dxf, arc7, 0.1, contour);
                    fun.drawBArc(dxf, arc9, 0.1, contour);
                }
                else
                {
                    Vector2 p58 = fun.Polar(Pus.ToV2(arc6.Center), (arc6.StartAngle) * pi / 180 - pi / 3.0, arc6.Radius);
                    Vector2 p59 = fun.Polar(Pus.ToV2(arc8.Center), (arc8.StartAngle) * pi / 180 - pi / 3.0, arc8.Radius);
                    Arc arc9 = fun.DrawArc3(fun.Polar(Pus.ToV2(arc6.Center), (arc6.StartAngle) * pi / 180, arc6.Radius), p59, p58);
                    //dxf.AddEntity(new EntityObject[] { arc6, arc8, arc9 });
                    fun.drawBArc(dxf, arc6, 0.1, contour);
                    fun.drawBArc(dxf, arc8, 0.1, contour);
                    fun.drawBArc(dxf, arc9, 0.1, contour);
                }
                
                //fun.PointRotate(p49_1, p54, 120 * pi / 180);//
            }

            //中心线
            Line line1_1 = new Line(p0_1, p0_2);
            line1_1.Linetype = Linetype.DashDot;
            line1_1.Lineweight = Lineweight.W25;
            line1_1.Layer = centre;
            dxf.AddEntity(line1_1);


            //标注

            if (dim == 0)
            {
                Vector2 v1 = fun.Polar(p0, pi / 2, td / 2 - h);
                Vector2 v2 = fun.Polar(p0, pi / -2, td / 2 - h);
                Vector2 v3 = fun.Polar(p0, pi / 2, td / 2.0 + h);
                Vector2 v4 = fun.Polar(v3, 0, l5 * p + p / 2.0);
                Vector2 v5 = fun.mirrorpoint(v4, p0_1, p0_2);
                Vector2 v6 = fun.Polar(p34, pi / 2, fun.CalDistance(p33, p34) / 2.0);
                Vector2 v8 = fun.PointRotate(p54, p55, ap_);
                Vector2 v9 = fun.Polar(p34, pi / 2, fun.CalDistance(p34, p33) / 2.0);
                Vector2 v10 = fun.Polar(v9, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v11 = fun.Polar(v10, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v12 = fun.Polar(p53, pi / -2, dmm);
                double L = 5 * (oal / 40.0);
                double height = 1.2 * (oal / 40.0);
                double arrowsize = (1.6 * (oal / 40.0));
                fun.dimrot1(dxf, v1, v2, 90, L, 2, height, arrowsize, 0.9, "  TCPD", "", "");
                fun.dimrot1(dxf, v4, v5, 90, L * 3, 2, height, arrowsize, 0.9, "TD", "", "");
                fun.dimrot1(dxf, p33, p34, -90, L, 2, height, arrowsize, 0.9, "DCONMS", "", "");
                fun.dimrot1(dxf, p0, v5, 180, L * 1.5, 2, height, arrowsize, 0.9, "TCL", "", "");
                fun.dimrot1(dxf, p0, p44, 0, L, 2, height, arrowsize, 0.9, "THL", "", "");
                fun.dimrot1(dxf, p54, fun.Polar(p54, 0, 0.1), 0, L / 2.0, 2, height, arrowsize, 0.9, " γp", "", "");
                fun.dimrot1(dxf, v8, fun.Polar(v8, pi / -2, 0.1), -155, L, 2, height, arrowsize, 0.9, " αp", "", "");
                fun.dimrot1(dxf, p34, p33,90, L, 2, height, arrowsize, 0.9, " A-A", "", "");
                fun.Singlelinearrow(dxf, "A", v9, 180, v10, v11, height, arrowsize);
                Text txt1 = new Text("A-A", v12, height, 0);
                dxf.AddEntity(txt1);
                try
                {
                    dn = Convert.ToDouble(data["dn"]);
                    fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN", "", "");
                }
                catch
                { }
                try
                {
                    drvsc = Convert.ToDouble(data["drvsc"]);
                    fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC", "", "");
                }
                catch
                { }
                try
                {
                    lu = Convert.ToDouble(data["lu"]);
                    Vector2 v7 = fun.Polar(p0, 0, lu);
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                    fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  LU", "", "");
                }
                catch
                {
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                }
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]);
                    fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL", "", "");
                }
                catch { }
                /*
                Vector2 v7 = fun.Polar(p0, 0, lu);
                fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN", "", "");
                fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC", "", "");
                fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                fun.dimrot1(dxf, p0, v7, 0, L *1.5, 2, height, arrowsize, 0.9, "  LU", "", "");
                fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL", "", "");*/
        }
            else
            {

                Vector2 v1 = fun.Polar(p0, pi / 2, td / 2 - h);
                Vector2 v2 = fun.Polar(p0, pi / -2, td / 2 - h);
                Vector2 v3 = fun.Polar(p0, pi / 2, td / 2.0 + h);
                Vector2 v4 = fun.Polar(v3, 0, l5 * p);
                Vector2 v5 = fun.mirrorpoint(v4, p0_1, p0_2);
                Vector2 v6 = fun.Polar(p34, pi / 2, fun.CalDistance(p33, p34) / 2.0);
                Vector2 v8 = fun.PointRotate(p54, p55, ap_);
                Vector2 v9 = fun.Polar(p34, pi / 2, fun.CalDistance (p34,p33)/2.0);
                Vector2 v10 = fun.Polar(v9, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v11 = fun.Polar(v10, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v12 = fun.Polar(p53, pi / -2, dmm);
                double tcpd = td - h * 2;
                double L = 5 * (oal / 40.0);
                double height = 1.2 * (oal / 40.0);
                double arrowsize = (1.6 * (oal / 40.0));
                fun.dimrot1(dxf, v1, v2, 90, L, 2, height, arrowsize, 0.9, "  TCPD="+tcpd , "", "");
                fun.dimrot1(dxf, v4, v5, 90, L * 3, 2, height, arrowsize, 0.9, "TD="+td, "", "");
                fun.dimrot1(dxf, p33, p34, -90, L, 2, height, arrowsize, 0.9, "DCONMS="+dmm, "", "");
                fun.dimrot1(dxf, p0, v5, 180, L * 1.5, 2, height, arrowsize, 0.9, "TCL="+tcl , "", "");
                fun.dimrot1(dxf, p0, p44, 0, L, 2, height, arrowsize, 0.9, "THL="+thl, "", "");
                fun.dimrot1(dxf, p54, fun.Polar(p54, 0, 0.1), 0, L / 2.0, 2, height, arrowsize, 0.9, "  γp="+ γp, "", "");
                fun.dimrot1(dxf, v8, fun.Polar(v8, pi/-2, 0.1), -155, L , 2, height, arrowsize, 0.9, " αp="+ ap, "", "");
                fun.Singlelinearrow(dxf, "A", v9, 180, v10, v11, height, arrowsize);
                Text txt1 = new Text("A-A", v12, height, 0);
                dxf.AddEntity(txt1);

                try
                {
                    dn = Convert.ToDouble(data["dn"]);
                   fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN="+dn, "", "");
                }
                catch
                { }
                try
                {
                    drvsc = Convert.ToDouble(data["drvsc"]);
                    fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC="+drvsc, "", "");
                }
                catch
                { }
                try
                {
                    lu = Convert.ToDouble(data["lu"]);
                    Vector2 v7 = fun.Polar(p0, 0, lu);
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL="+oal, "", "");
                    fun.dimrot1(dxf, p0, v7, 0, L *1.5, 2, height, arrowsize, 0.9, "  LU="+lu, "", "");
                }
                catch
                {
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL="+oal, "", "");
                }
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]);
                    fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL="+drvl, "", "");
                }
                catch { }
                /*
                Vector2 v7 = fun.Polar(p0, 0, lu);
                fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN", "", "");
                fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC", "", "");
                fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                fun.dimrot1(dxf, p0, v7, 0, L *1.5, 2, height, arrowsize, 0.9, "  LU", "", "");
                fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL", "", "");*/
            }

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void pointedtap(Dictionary<string, Object> data)//螺尖丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double dim = 1;
            double scale = 5;
            /*double tcl = 4 * scale;
            double td = 4 * scale;
            double thl = 16 * scale;
            double oal = 40 * scale;
            double dmm = 3.8 * scale;
            double dn;
            double drvl;
            double lu;
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = dmm - dmm / 10.0;
            }
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.25 * (oal / 40.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = 4 * scale;
            double p = 1*scale ;//螺距
            double h = 0.866025*scale ;//根据螺纹牙型标准中的p得知h牙高的值
            double k = 8.30;//螺纹头部断开角度
            double k_ = k * pi / 180;
            double an = 0;
            double an_ = an * pi / 180;
            double l5 = 4;
            double ap = 0;
            double γp = 5;
            double ap_ = ap * pi / 180;


            double fha = 85;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;
            */
            double tcl = Convert.ToDouble(data["tcl"]) * scale;
            double td = Convert.ToDouble(data["td"]) * scale;
            double thl = Convert.ToDouble(data["thl"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double dmm = Convert.ToDouble(data["dconms"]) * scale;
            double dn;
            double drvl;
            double lu;
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = dmm - dmm / 10.0;
            }
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.25 * (oal / 40.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = Convert.ToDouble(data["drvsc"]) * scale;
            double p = Convert.ToDouble(data["tp"]) * scale;//螺距
            double h = Convert.ToDouble(data["h"]) * scale;//根据螺纹牙型标准中的p得知h牙高的值
            double k = Convert.ToDouble(data["k"]);//螺纹头部断开角度
            double k_ = k * pi / 180;
            double an = Convert.ToDouble(data["an"]);
            double l5 = Convert.ToDouble(data["l5"]);
            double ap = Convert.ToDouble(data["ap"]);
            double γp = Convert.ToDouble(data["rp"]);

            double fha = 85;//定值，螺纹线偏角，看情况改
             double ap_ =0;
            double fha_ = fha * pi / 180;
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, 0, oal + 5);
            Vector2 p0_2 = fun.Polar(p0, pi, 5);
            Vector2 p1_1 = fun.Polar(p0, pi / 2, td / 2.0 - h);
            Vector2 p1_2 = fun.Polar(p1_1, k_, oal);
            Vector2 p1_3 = fun.Polar(p0, pi / -2, td / 2.0 - h);
            Vector2 p1_4 = fun.Polar(p1_3, -k_, oal);
            //虚拟矩阵，不显示
            Vector2 p1 = fun.Polar(p0, pi / 2, td / 2.0);
            Vector2 p2 = fun.Polar(p1, 0, thl);
            Vector2 p3 = fun.Polar(p2, pi / -2, td / 2.0);
            Vector2 p4 = fun.Polar(p0, pi / -2, td / 2.0);
            //螺尖丝锥头部缺失
            Vector2 p60 = fun.Polar(p0, pi / 2, td / 10.0);
            Vector2 p61 = new Vector2(p * l5, (5.376 / 20.0) * td);
            //Vector2 p62 = fun.Polar(p0, pi / -2, td / 4.0);
            Vector2 p63 = fun.Polar(p0, pi / -2,td/4.0);
            Vector2 p64 = new Vector2(p * l5, (0.7 / 20.0) * td);
            Vector2 p65 = new Vector2 (p*l5, (5.376 / 20.0) * td+0.1*(td/20.0));
            Vector2 p66 = fun.Polar(p65, pi , oal);
            Vector2 p67 = fun.Polar(p61, 0, 1.835 * (td / 20.0));
            Vector2 p72 = fun.Polar(p67, 90.001 * pi / 180, oal);
            Arc arc3 = fun.DrawArc5(p61, new Line(p65, p66), p60);
            Arc arc4 = fun.DrawArc5(p64, new Line(p67, p72), p61);
            Line line4 = new Line(p63, p64);
            //dxf.AddEntity(new EntityObject[] { arc3,arc4, line4 });
            
            fun.drawBArc(dxf, arc3, 0.3, contour );
            fun.drawBArc(dxf, arc4, 0.3, contour);
            fun.drawBline(dxf, line4, 0.3, contour);
            //螺纹
            Vector2 p7 = p0;
            Vector2 p5 = p0;
            Vector2 p6 = p0;
            Vector2 p8 = p0;
            Vector2 p9 = p0;
            Vector2 p10 = p0;
            Vector2 p11 = p0;
            Vector2 p12 = p0;
            Vector2 p13 = p0;
            Vector2 p14 = p0;
            Vector2 p15 = p0;
            Vector2 p16 = p0;
            Vector2 p17 = p0;
            Vector2 p18 = p1_1;
            Vector2 p19 = p0;
            Vector2 p20 = p0;
            Vector2 p21 = p0;
            var polyline1 = Pus.AddPointsToLwPolyLine(p0);
            var polyline1_1 = Pus.AddPointsToLwPolyLine(p0);
            var polyline2 = Pus.AddPointsToLwPolyLine(p0);
            
            for (int i = 0; i < l5; i++)
            {
                if (i == 0)
                {
                    p5 = fun.Polar(p7, pi / 2, td / 2 - h);
                    p10 = new Vector2(p5.X + (td / 2 - h) / Math.Tan(fha_), -p5.Y);
                }
                else
                {
                    p5 = p7;
                    p10 = p13;
                }
                p6 = new Vector2(p5.X + p / 2.0, p5.Y + h);
                p7 = new Vector2(p6.X + (p6.X - p5.X), p5.Y);
                p8 = fun.Inters(p5, p6, p1_1, p1_2);
                Vector2 p8_1 = fun.Polar(p8, pi / 2, h);
                p9 = fun.Inters(p6, p7, p1_1, p1_2);
                Vector2 p9_1 = fun.Polar(p9, pi / 2, h);
                p11 = new Vector2(p8.X + (td / 2 - h) / Math.Tan(fha_), -p8.Y);
                p12 = new Vector2(p9.X + (td / 2 - h) / Math.Tan(fha_), -p9.Y);
                p13 = new Vector2(p7.X + (td / 2 - h) / Math.Tan(fha_), -p7.Y);
                p14 = fun.Inters(p5, p10, p0_1, p0_2);
                p15 = fun.Inters(p8, p11, p0_1, p0_2);
                p16 = fun.Inters(p9, p12, p0_1, p0_2);
                p17 = fun.Inters(p7, p13, p0_1, p0_2);
                p19 = fun.Polar(p18, pi / -2, td - 2 * h);
                p20 = fun.Polar(p19, 0, (td / 2 - h) / Math.Tan(fha_));
                
                Vector2 p68 = fun.Inters(p14, p10, p63, p64);
                Vector2 p69 = fun.Inters(p15, p11, p63, p64);
                Vector2 p70 = fun.Inters(p16, p12, p63, p64);
                Vector2 p71 = fun.Inters(p17, p13, p63, p64);
                if (p68.Y >0)
                {
                    p68 = fun.Inters(p14, p10, p0_1, p0_2);
                }
                else
                {
                    p68 = fun.Inters(p14, p10, p63, p64);
                }
                if(p69.Y > 0)
                {
                    p69 = fun.Inters(p15, p11, p0_1, p0_2);
                }
                else
                {
                    p69 = fun.Inters(p15, p11, p63, p64);
                }
                if (p70.Y > 0)
                {
                    p70 = fun.Inters(p16, p12, p0_1, p0_2);
                }
                else
                {
                    p70 = fun.Inters(p16, p12, p63, p64);
                }
                if (p71.Y > 0)
                {
                    p71 = fun.Inters(p17, p13, p0_1, p0_2);
                }
                else
                {
                    p71 = fun.Inters(p17, p13, p63, p64);
                }
                polyline1 = Pus.AddPointsToLwPolyLine(p5, p8, p9, p7);
                polyline1_1 = Pus.AddPointsToLwPolyLine(p8, p8_1, p8, p9, p9_1, p9);
                polyline2 = Pus.AddPointsToLwPolyLine(p68, p10, p11, p69, p11, p12, p70, p12, p13, p71, p13);
                var polyline3 = Pus.AddPointsToLwPolyLine(p18, p19, p20);

                p21 = fun.Polar(p0, pi / 2, h);
                Vector2 p21_3 = fun.Polar(p0, 0, (td / 2 - h) / Math.Tan(fha_));
                var polyline4 = Pus.OffsetLwPolyline(polyline1, p21);
                var polyline4_1 = Pus.MirrorPolyline(polyline4, p0_1, p0_2);
                var polyline4_2 = Pus.OffsetLwPolyline(polyline4_1, p21_3);
                //dxf.AddEntity(new EntityObject[] { polyline1, polyline1_1, polyline2, polyline3, polyline4, polyline4_2 });
                fun.PolyFill(dxf, polyline1, 0.3, contour);
                fun.PolyFill(dxf, polyline1_1, 0.5, contour);
                
                fun.PolyFill(dxf, polyline2, 0.3, contour);
                
                fun.PolyFill(dxf, polyline3, 0.5, contour); 
                fun.PolyFill(dxf, polyline4, 0.5, contour);
                fun.PolyFill(dxf, polyline4_2, 0.5, contour);
            }
            double a1 = (thl - p * l5) / (p);
            int a2 = (int)a1;
            for (int j = 0; j < a2; j++)
            {
                p5 = p7;
                p6 = new Vector2(p5.X + p / 2.0, p5.Y + h);
                Vector2 p6_1 = fun.Polar(p6, pi / 2, h);
                p7 = new Vector2(p6.X + (p6.X - p5.X), p5.Y);
                p8 = new Vector2(p5.X + (td / 2 - h) / Math.Tan(fha_), -p5.Y);
                p9 = new Vector2(p6.X + (td / 2 - h) / Math.Tan(fha_), -p6.Y);
                p10 = new Vector2(p7.X + (td / 2 - h) / Math.Tan(fha_), -p7.Y);
                p14 = fun.Inters(p8, p5, p0_1, p0_2);
                p15 = fun.Inters(p9, p6, p0_1, p0_2);
                p16 = fun.Inters(p10, p7, p0_1, p0_2);
                polyline2 = Pus.AddPointsToLwPolyLine(p14, p8, p9, p15, p9, p10, p16, p10);
                polyline1 = Pus.AddPointsToLwPolyLine(p5, p6, p7);
                polyline1_1 = Pus.AddPointsToLwPolyLine(p6, p6_1);
                p21 = new Vector2(0, h);
                Vector2 p21_1 = fun.Polar(p0, 0, (td / 2 - h) / Math.Tan(fha_));
                var polyline4 = Pus.OffsetLwPolyline(polyline1, p21);
                var polyline4_1 = Pus.MirrorPolyline(polyline4, p0_1, p0_2);
                var polyline4_2 = Pus.OffsetLwPolyline(polyline4_1, p21_1);
                //dxf.AddEntity(new EntityObject[] { polyline1,polyline1_1, polyline2,polyline4 , polyline4_2 });
                fun.PolyFill(dxf, polyline1, 0.3, contour);
                fun.PolyFill(dxf, polyline1_1, 0.5, contour);
                fun.PolyFill(dxf, polyline2, 0.3, contour);
                fun.PolyFill(dxf, polyline4, 0.5, contour);
                fun.PolyFill(dxf, polyline4_2, 0.5, contour);
            }
            Vector2 p22 = fun.Polar(p0, pi / -2, td / 2.0);
            Vector2 p23 = fun.Polar(p22, 0, (td / 2 - h) / Math.Tan(fha_));
            var polyline5 = Pus.AddPointsToLwPolyLine(p0, p22, p23);
            //dxf.AddEntity(new EntityObject[] { polyline5 });
            fun.PolyFill(dxf, polyline5, 0.5, contour);
            //柄部
            Vector2 p25 = fun.Polar(p7, pi / 2, h);
            Vector2 p25_1 = new Vector2(p25.X, dn / 2.0);
            Vector2 p26 = fun.Polar(p25, pi / -2, td);
            Vector2 p27 = fun.Polar(p26, 0, (td / 2 - h) / Math.Tan(fha_));
            Vector2 p27_1 = new Vector2(p27.X, -dn / 2.0);
            Vector2 p28_1 = fun.Polar(p7, pi / -2, td - 2 * h);
            Vector2 p28 = fun.Polar(p28_1, 0, (td / 2 - h) / Math.Tan(fha_));
            Vector2 p29 = fun.Polar(p25_1, 0, lu - thl);
            Vector2 p30 = new Vector2(p29.X, dmm / 2.0);
            Vector2 p31 = fun.mirrorpoint(p29, p0_1, p0_2);
            Vector2 p32 = fun.mirrorpoint(p30, p0_1, p0_2);
            Vector2 p33 = fun.Polar(p30, 0, oal - lu);
            Vector2 p34 = fun.mirrorpoint(p33, p0_1, p0_2);
            Vector2 p35_1 = fun.Polar(p33, pi / -2, dmm / 2.0 - dmm / 2.0 / 10.0);
            Vector2 p35 = fun.Polar(p35_1, pi, 0.42 * (oal / 40.0));
            Vector2 p36 = fun.Polar(p33, pi, drvl);
            Vector2 p37 = new Vector2(p36.X, p35.Y);
            Vector2 p38 = fun.mirrorpoint(p35, p0_1, p0_2);
            Vector2 p39 = fun.mirrorpoint(p36, p0_1, p0_2);
            Vector2 p40 = fun.mirrorpoint(p37, p0_1, p0_2);
            Vector2 p41 = new Vector2(p35.X, p36.Y);
            Vector2 p42 = new Vector2(p38.X, p39.Y);
            var polyline6 = Pus.AddPointsToLwPolyLine(p25, p28, p27, p27_1, p31, p32, p42, p40, p38, p35, p36, p41, p30, p32, p29, p25_1);
            var polyline7 = Pus.AddPointsToLwPolyLine(p42, p40, p38, p39, p42, p39, p40, p38, p35, p36, p41, p37, p35, p37, p36, p41);
            Line line1 = new Line(p33, p34);
            Arc arc1 = fun.DrawArc5(p35, line1, p41);
            Arc arc2 = fun.DrawArc5(p42, line1, p38);
            //dxf.AddEntity(new EntityObject[] { polyline6, polyline7, arc1, arc2 });
            fun.PolyFill(dxf, polyline6, 0.5, contour);
            fun.PolyFill(dxf, polyline7, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            fun.drawBArc(dxf, arc2, 0.5, contour);
            //颈部
            Vector2 p43 = fun.Polar(p7, pi / -2, oal);
            Vector2 p44 = fun.Inters(p0_1, p0_2, p7, p43);
            Vector2 p45 = fun.Polar(p44, 0, (lu - thl) * (1.75 / 9.95));
            Vector2 p46 = fun.Polar(p7, 0, (lu - thl) * (1.75 / 9.95));
            Vector2 p47 = fun.Polar(p28, 0, (lu - thl) * (3.5 / 9.95));
            p47 = fun.Polar(p28, 0, p45.X - p44.X);
            Vector2 p45_1 = fun.Polar(fun.Polar(p45, 0, (lu - (thl)) * (4.5 / 50.0)), pi / 2, fun.CalDistance(p45, p46) / 2.0);
            Vector2 p48_1 = fun.Polar(p45_1, pi / -2, oal);
            Vector2 p48 = fun.Inters(fun.Polar(p27, pi / 2, (dmm - dn) / 2.0), fun.Polar(p31, pi / 2, (dmm - dn) / 2.0), p45_1, p48_1);
            var polyline13 = Pus.AddPointsToLwPolyLine(p44, p45, p45_1, p46, p7);
            polyline13.Vertexes[1].Bulge = Math.Tan((60 * pi / 180) / 4);
            polyline13.Vertexes[2].Bulge = Math.Tan((60 * pi / 180) / 4);
            //dxf.AddEntity(polyline13);
            var polyline14 = Pus.AddPointsToLwPolyLine(p28, p47, p48);
            polyline14.Vertexes[1].Bulge = -Math.Tan((60 * pi / 180) / 4);
            //dxf.AddEntity(polyline14);
            fun.PolyFill(dxf, polyline13, 0.5, contour);
            fun.PolyFill(dxf, polyline14, 0.5, contour);
            //侧面
            try
            {
                drvsc = Convert.ToDouble(data["drvsc"]) * scale;

            }
            catch
            {
                drvsc = td;
            }
            Vector2 p50 = p0;
            Vector2 p51 = p0;
            Vector2 p49_1 = fun.Polar(p0, pi, oal / 1.5);
            Vector2 p49 = fun.Polar(p0, 0, oal + oal / 3.0);
            p50 = fun.Polar(p49, pi / 2, drvsc / 2.0);
            Vector2 p50_1 = fun.Polar(p50, pi + pi / 4, drvsc / 10.0);
            Vector2 p50_2 = fun.Polar(p50, pi / -4, drvsc / 10.0);
            p51 = fun.Polar(p49, 0, drvsc / 2.0);
            Vector2 p51_1 = fun.Polar(p51, pi - pi / 4, drvsc / 10.0);
            Vector2 p51_2 = fun.Polar(p51, pi + pi / 4, drvsc / 10.0);
            Vector2 p52 = fun.Polar(p49, pi / -2, drvsc / 2.0);
            Vector2 p52_1 = fun.Polar(p52, pi / 4, drvsc / 10.0);
            Vector2 p52_2 = fun.Polar(p52, pi - pi / 4, drvsc / 10.0);
            Vector2 p53 = fun.Polar(p49, pi, drvsc / 2.0);
            Vector2 p53_1 = fun.Polar(p53, pi / -4, drvsc / 10.0);
            Vector2 p53_2 = fun.Polar(p53, pi / 4, drvsc / 10.0);
            var polyline9 = Pus.AddPointsToLwPolyLine(p50_1, p50_2, p51_1, p51_2, p52_1, p52_2, p53_1, p53_2, p50_1);
            polyline9.Vertexes[0].Bulge = -Math.Tan((90 * pi / 180) / 4);
            polyline9.Vertexes[2].Bulge = -Math.Tan((90 * pi / 180) / 4);
            polyline9.Vertexes[4].Bulge = -Math.Tan((90 * pi / 180) / 4);
            polyline9.Vertexes[6].Bulge = -Math.Tan((90 * pi / 180) / 4);
            fun.PolyFill(dxf, polyline9, 0.5, contour);
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = polyline9.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = polyline9.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)polyline9.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)polyline9.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 3 * (oal / 40.0), hline1, harc1, hatching);
            //左视
            Circle circle1 = new Circle(p49_1, dmm / 2.0);
            Circle circle2 = new Circle(p49_1, td / 2.0);//外轮廓参照
            Arc arc2_1 = fun.DrawArc4(fun.Polar(p49_1, 0, td / 2.0), circle2.Radius, fun.Polar(p49_1, 179.99 * pi / 180, td / 2.0), 0);
            Vector2 p54 = fun.Polar(p49_1, pi / 2, td / 2.0 + 2 * h);
            Vector2 p54_1 = fun.Polar(fun.PointRotate(p54, p49_1, ap_), pi / -4, dmm * (1 / 19.0));
            Vector2 p55 = fun.Polar(p49_1, pi / 6, td / 2.0 + 2 * h);
            Vector2 p56 = fun.Polar(p49_1, pi / 2, td / 2.0 - td / 15.0 + 2 * h);
            Vector2 p57 = fun.Polar(p49_1, pi / 6, td / 2.0 - td / 15.0 + 2 * h);

            /*

            Vector2 p73 = fun.Polar(p54, -ap_ - 31 * pi / 180, 5.52 / 20.0 * td);
            Vector2 p74 = fun.PointRotate(fun.PointRotate(p54, p49_1, ap_),p54, 300 * pi / 180 );
            Vector2 p75 = fun.Polar(p74, -ap_ - 31 * pi / 180, 8.16 / 20.0 * td);
            Vector2 p76_1 = fun.Polar(p54_1, pi / 2, dmm / 4.0);
            Vector2 p76 = fun.Polar(p76_1, pi, oal);
            Vector2 p77 = fun.Polar(p76, 0, oal);
            Line line5 = new Line(p54, p73);
            Line line6 = new Line(p74, p75);
            Arc arc10 = fun.DrawArc5(p75, new Line(p76, p77), p73);
            //dxf.AddEntity(new EntityObject[] { line5, line6, arc10 });
            fun.drawBArc(dxf, arc10, 0.5, contour);
            fun.drawBline(dxf, line5, 0.5, contour);
            fun.drawBline(dxf, line6, 0.5, contour);


            Vector2 p78 = fun.PointRotate(p49_1, p54, 120 * pi / 180 );
            Vector2 p79 = fun.PointRotate(p49_1, p73, 120 * pi / 180 );
            Vector2 p80 = fun.PointRotate(p54, p55, ap_  );
            Vector2 p81 = fun.PointRotate(p49_1, p75, 120 * pi / 180 );
            Vector2 p82 = fun.PointRotate(p49_1, p76, 120 * pi / 180 );
            Vector2 p83 = fun.PointRotate(p49_1, p77, 120 * pi / 180 );
            Vector2 p84 = fun.PointRotate(p49_1, p73, 120 * pi / 180 );
            Line line7 = new Line(p78, p79);
            Line line8 = new Line(p80, p81);
            Arc arc11 = fun.DrawArc5(p81, new Line(p82, p83), p84);
            fun.drawBArc(dxf, arc11, 0.5, contour);
            fun.drawBline(dxf, line7, 0.5, contour);
            fun.drawBline(dxf, line8, 0.5, contour);
            //dxf.AddEntity(new EntityObject[] { line7, line8, arc11 });

            Vector2 p85 = fun.PointRotate(p49_1, p54, -120 * pi / 180 + ap_);
            Vector2 p86 = fun.PointRotate(p49_1, p73, -120 * pi / 180 + ap_);
            Vector2 p87 = fun.PointRotate(p49_1, p74, -120  * pi / 180 + ap_);
            Vector2 p88 = fun.PointRotate(p49_1, p75, -120  * pi / 180 + ap_);
            Vector2 p89 = fun.PointRotate(p49_1, p76, -120  * pi / 180 + ap_);
            Vector2 p90 = fun.PointRotate(p49_1, p77, -120  * pi / 180 + ap_);
            Vector2 p91 = fun.PointRotate(p49_1, p73, -120  * pi / 180 + ap_);
            Line line9 = new Line(p85, p86);
            Line line10 = new Line(p87, p88);
            Arc arc12 = fun.DrawArc5(p88, new Line(p89, p90), p91);
            fun.drawBArc(dxf, arc12, 0.5, contour);
            fun.drawBline(dxf, line9, 0.5, contour);
            fun.drawBline(dxf, line10, 0.5, contour);
            */

            Circle circle3 = new Circle(p49_1 , dmm / 2.0);
            circle3.Linetype = Linetype.Dashed;
            circle3.Lineweight = Lineweight.W35;
            circle3.Layer = centre;
            dxf.AddEntity(circle3);
            Circle circle4 = new Circle(p49_1, dmm / 4.0);
            circle4.Linetype = Linetype.Dashed;
            circle4.Lineweight = Lineweight.W35;
            circle4.Layer = centre;
            dxf.AddEntity(circle4);
            for (int j = 0; j < 3; j++)
            {
                Arc arc5 = fun.DrawArc(p55, p49_1, p54);
                Vector2 arc5_1 = fun.PointRotate(Pus.ToV2(arc5.Center), fun.Polar(Pus.ToV2(arc5.Center), arc5.StartAngle * pi / 180, arc5.Radius), 120 * j * pi / 180);
                Vector2 arc5_2 = fun.PointRotate(Pus.ToV2(arc5.Center), fun.Polar(Pus.ToV2(arc5.Center), arc5.EndAngle * pi / 180, arc5.Radius), 120 * j * pi / 180);
                arc5 = fun.DrawArc(arc5_1, Pus.ToV2(arc5.Center), arc5_2);
                Arc arc7 = fun.DrawArc(p57, p49_1, p56);
                Vector2 arc7_1 = fun.PointRotate(Pus.ToV2(arc7.Center), fun.Polar(Pus.ToV2(arc7.Center), arc7.StartAngle * pi / 180, arc7.Radius), 120 * j * pi / 180);
                Vector2 arc7_2 = fun.PointRotate(Pus.ToV2(arc7.Center), fun.Polar(Pus.ToV2(arc7.Center), arc7.EndAngle * pi / 180, arc7.Radius), 120 * j * pi / 180);
                arc7 = fun.DrawArc(arc7_1, Pus.ToV2(arc7.Center), arc7_2);
                Arc arc6 = fun.Rotatingcircle(arc5, p54, ap_);
                Vector2 arc6_1 = fun.PointRotate(Pus.ToV2(arc6.Center), fun.Polar(Pus.ToV2(arc6.Center), arc6.StartAngle * pi / 180, arc6.Radius), 120 * j * pi / 180);
                Vector2 arc6_2 = fun.PointRotate(Pus.ToV2(arc6.Center), fun.Polar(Pus.ToV2(arc6.Center), arc6.EndAngle * pi / 180, arc6.Radius), -120 * j * pi / 180);
                arc6 = fun.DrawArc(arc6_1, Pus.ToV2(arc6.Center), arc6_2);
                Arc arc8 = fun.Rotatingcircle(arc7, p56, ap_);
                Vector2 arc8_1 = fun.PointRotate(Pus.ToV2(arc8.Center), fun.Polar(Pus.ToV2(arc8.Center), arc8.StartAngle * pi / 180, arc8.Radius), 120 * j * pi / 180);
                Vector2 arc8_2 = fun.PointRotate(Pus.ToV2(arc8.Center), fun.Polar(Pus.ToV2(arc8.Center), arc8.EndAngle * pi / 180, arc8.Radius), -120 * j * pi / 180);
                arc8 = fun.DrawArc(arc8_1, Pus.ToV2(arc8.Center), arc8_2);

                

                    Vector2 p73 = fun.Polar(arc5_2, -ap_ - 31 * pi / 180 - 120 * j * pi / 180, 5.52 / 20.0 * td);
                    Vector2 p74 = fun.PointRotate(fun.PointRotate(p54, p49_1, ap_), arc5_2, 300 * pi / 180);
                    Vector2 p75 = fun.Polar(p74, -ap_ - 31 * pi / 180 - 120 * j * pi / 180, 8.16 / 20.0 * td);
                    Vector2 p76_1 = fun.Polar(p49_1 , pi / 2 - 120 * j * pi / 180, dmm / 4.0);
              
                    Vector2 p76 = fun.Polar(p76_1, pi - 120 * j * pi / 180, oal);
                    Vector2 p77 = fun.Polar(p76, 0 - 120 * j * pi / 180, oal);
             
                Line line5 = new Line(arc5_2, p73);
                    Line line6 = new Line(p74, p75);
                    Arc arc10 = fun.DrawArc5(p75, new Line(p76, p77), p73);
                    //dxf.AddEntity(new EntityObject[] { line5, line6, arc10 });
                    fun.drawBArc(dxf, arc10, 0.5, contour);
                    fun.drawBline(dxf, line5, 0.5, contour);
                    fun.drawBline(dxf, line6, 0.5, contour);
              

                if (ap_ == 0)
                {
                    Vector2 p58 = fun.Polar(Pus.ToV2(arc5.Center), (arc5.StartAngle) * pi / 180 - pi / 3.0, arc5.Radius);
                    Vector2 p59 = fun.Polar(Pus.ToV2(arc7.Center), (arc7.StartAngle) * pi / 180 - pi / 3.0, arc7.Radius);
                    Arc arc9 = fun.DrawArc3(fun.Polar(Pus.ToV2(arc5.Center), (arc5.StartAngle) * pi / 180, arc5.Radius), p59, p58);
                    //dxf.AddEntity(new EntityObject[] { arc5, arc7, arc9 });
                    fun.drawBArc(dxf, arc5, 0.5, contour);
                    fun.drawBArc(dxf, arc7, 0.5, contour);
                    fun.drawBArc(dxf, arc9, 0.5, contour);
                }
                else
                {
                    Vector2 p58 = fun.Polar(Pus.ToV2(arc6.Center), (arc6.StartAngle) * pi / 180 - pi / 3.0, arc6.Radius);
                    Vector2 p59 = fun.Polar(Pus.ToV2(arc8.Center), (arc8.StartAngle) * pi / 180 - pi / 3.0, arc8.Radius);
                    Arc arc9 = fun.DrawArc3(fun.Polar(Pus.ToV2(arc6.Center), (arc6.StartAngle) * pi / 180, arc6.Radius), p59, p58);
                    //dxf.AddEntity(new EntityObject[] { arc6, arc8, arc9 });
                    fun.drawBArc(dxf, arc6, 0.5, contour);
                    fun.drawBArc(dxf, arc8, 0.5, contour);
                    fun.drawBArc(dxf, arc9, 0.5, contour);
                }

                //fun.PointRotate(p49_1, p54, 120 * pi / 180);//
            }

            //中心线
            Line line1_1 = new Line(p0_1, p0_2);
            line1_1.Linetype = Linetype.DashDot;
            line1_1.Lineweight = Lineweight.W25;
            line1_1.Layer = centre;
            dxf.AddEntity(line1_1);


            //标注

            if (dim == 0)
            {
                Vector2 v1 = fun.Polar(p0, pi / 2, td / 2 - h);
                Vector2 v2 = fun.Polar(p0, pi / -2, td / 2 - h);
                Vector2 v3 = fun.Polar(p0, pi / 2, td / 2.0 + h);
                Vector2 v4 = fun.Polar(v3, 0, l5 * p + p / 2.0);
                Vector2 v5 = fun.mirrorpoint(v4, p0_1, p0_2);
                Vector2 v6 = fun.Polar(p34, pi / 2, fun.CalDistance(p33, p34) / 2.0);
                Vector2 v8 = fun.PointRotate(p54, p55, ap_);
                Vector2 v9 = fun.Polar(p34, pi / 2, fun.CalDistance(p34, p33) / 2.0);
                Vector2 v10 = fun.Polar(v9, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v11 = fun.Polar(v10, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v12 = fun.Polar(p53, pi / -2, dmm );
                double L = 5 * (oal / 40.0);
                double height = 1.2 * (oal / 40.0);
                double arrowsize = (1.6 * (oal / 40.0));
                fun.dimrot1(dxf, v1, v2, 90, L, 2, height, arrowsize, 0.9, "  TCPD", "", "");
                fun.dimrot1(dxf, v4, v5, 90, L * 3, 2, height, arrowsize, 0.9, "TD", "", "");
                fun.dimrot1(dxf, p33, p34, -90, L, 2, height, arrowsize, 0.9, "DCONMS", "", "");
                fun.dimrot1(dxf, p0, v5, 180, L * 1.5, 2, height, arrowsize, 0.9, "TCL", "", "");
                fun.dimrot1(dxf, p0, p44, 0, L, 2, height, arrowsize, 0.9, "THL", "", "");
                fun.dimrot1(dxf, p54, fun.Polar(p54, 0, 0.1), 0, L / 2.0, 2, height, arrowsize, 0.9, " γp=" + γp, "", "");
                fun.dimrot1(dxf, v8, fun.Polar(v8, pi / -2, 0.1), -155, L, 2, height, arrowsize, 0.9, " αp=" + ap, "", "");
                fun.Singlelinearrow(dxf, "A", v9, 180, v10, v11, height, arrowsize);
                Text txt1 = new Text("A-A", v12, height, 0);
                dxf.AddEntity(txt1);

                try
                {
                    dn = Convert.ToDouble(data["dn"]) * scale;
                    fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN", "", "");
                }
                catch
                { }
                try
                {
                    drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                    fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC", "", "");
                }
                catch
                { }
                try
                {
                    lu = Convert.ToDouble(data["lu"]) * scale;
                    Vector2 v7 = fun.Polar(p0, 0, lu);
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                    fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  LU", "", "");
                }
                catch
                {
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                }
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]) * scale;
                    fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL", "", "");
                }
                catch { }
                /*
                Vector2 v7 = fun.Polar(p0, 0, lu);
                fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN", "", "");
                fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC", "", "");
                fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                fun.dimrot1(dxf, p0, v7, 0, L *1.5, 2, height, arrowsize, 0.9, "  LU", "", "");
                fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL", "", "");*/
            }
            else
            {

                Vector2 v1 = fun.Polar(p0, pi / 2, td / 2 - h);
                Vector2 v2 = fun.Polar(p0, pi / -2, td / 2 - h);
                Vector2 v3 = fun.Polar(p0, pi / 2, td / 2.0 + h);
                Vector2 v4 = fun.Polar(v3, 0, l5 * p);
                Vector2 v5 = fun.mirrorpoint(v4, p0_1, p0_2);
                Vector2 v6 = fun.Polar(p34, pi / 2, fun.CalDistance(p33, p34) / 2.0);
                Vector2 v8 = fun.PointRotate(p54, p55, ap_);
                Vector2 v9 = fun.Polar(p34, pi / 2, fun.CalDistance(p34, p33) / 2.0);
                Vector2 v10 = fun.Polar(v9, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v11 = fun.Polar(v10, 0, 5 * (oal / 40.0) / 4.0);
                Vector2 v12 = fun.Polar(p53, pi / -2, dmm );
                double tcpd = td - h * 2;
                double L = 5 * (oal / 40.0);
                double height = 1.2 * (oal / 40.0);
                double arrowsize = (1.6 * (oal / 40.0));
                fun.dimrot1(dxf, v1, v2, 90, L, 2, height, arrowsize, 0.9, "  TCPD=" + tcpd / scale, "", "");
                fun.dimrot1(dxf, v4, v5, 90, L * 3, 2, height, arrowsize, 0.9, "TD=" + td / scale, "", "");
                fun.dimrot1(dxf, p33, p34, -90, L, 2, height, arrowsize, 0.9, "DCONMS=" + dmm / scale, "", "");
                fun.dimrot1(dxf, p0, v5, 180, L * 1.5, 2, height, arrowsize, 0.9, "TCL=" + tcl / scale, "", "");
                fun.dimrot1(dxf, p0, p44, 0, L, 2, height, arrowsize, 0.9, "THL=" + thl / scale, "", "");
                fun.dimrot1(dxf, p54, fun.Polar(p54, 0, 0.1), 0, L / 2.0, 2, height, arrowsize, 0.9, "  γp=" + γp, "", "");
                fun.dimrot1(dxf, v8, fun.Polar(v8, pi / -2, 0.1), -155, L, 2, height, arrowsize, 0.9, " αp=" + ap, "", "");
                fun.Singlelinearrow(dxf, "A", v9, 180, v10, v11, height, arrowsize);
                Text txt1 = new Text("A-A", v12, height, 0);
                dxf.AddEntity(txt1);
                try
                {
                    dn = Convert.ToDouble(data["dn"]) * scale;
                    fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN=" + dn / scale, "", "");
                }
                catch
                { }
                try
                {
                    drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                    fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC=" + drvsc / scale, "", "");
                }
                catch
                { }
                try
                {
                    lu = Convert.ToDouble(data["lu"]) * scale;
                    Vector2 v7 = fun.Polar(p0, 0, lu);
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL=" + oal / scale, "", "");
                    fun.dimrot1(dxf, p0, v7, 0, L * 1.5, 2, height, arrowsize, 0.9, "  LU=" + lu / scale, "", "");
                }
                catch
                {
                    fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL=" + oal / scale, "", "");
                }
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]) * scale;
                    fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL=" + drvl / scale, "", "");
                }
                catch { }
                /*
                Vector2 v7 = fun.Polar(p0, 0, lu);
                fun.dimrot1(dxf, p31, p29, -90, L / 2.0, 2, height, arrowsize, 0.9, "  DN", "", "");
                fun.dimrot1(dxf, p50, p51, -45, L / 2.0, 2, height, arrowsize, 0.9, "  DRVSC", "", "");
                fun.dimrot1(dxf, p0, v6, 0, L * 2, 2, height, arrowsize, 0.9, "OAL", "", "");
                fun.dimrot1(dxf, p0, v7, 0, L *1.5, 2, height, arrowsize, 0.9, "  LU", "", "");
                fun.dimrot1(dxf, p39, p42, 180, L * 1.5 + p42.Y, 2, height, arrowsize, 0.9, "DRVL", "", "");*/
            }


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }




            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void extrudedtap(Dictionary<string, Object> data)//挤压丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double dim = 1;
            double scale = 5;
           /*double tcl = 4 * scale;
            double td = 12 * scale;
            double a = 10 * scale;
            double tcpd = 10 * scale;
            double thl = 16 * scale;
            double ls = 20 * scale;
            double oal = 46 * scale;
            double dmm = 8 * scale;
            double dn;
            double drvl;
            double lu;
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = dmm - dmm / 10.0;
            }
            try
            {
                ls = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                ls = oal * (20.0 / 46.0);
            }
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.5 * (oal / 46.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = 4 * scale;
            double p = 1 * scale;//螺距
            double h = 0.866025 * scale;//根据螺纹牙型标准中的p得知h牙高的值
            double k = 10;//螺纹头部断开角度
            double k_ = k * pi / 180;
            double an = 0;
            double an_ = an * pi / 180;
            double l5 = 4;
            double ap = 0;
            double γp = 5;
            double ap_ = ap * pi / 180;
            double fha = 83;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;*/

          
            
            double a = Convert.ToDouble(data["dconms"]) * scale;
            double thl = Convert.ToDouble(data["thl"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double dmm = Convert.ToDouble(data["dconms"]) * scale;
            double dn;
            double drvl;
            double lu;
            double tcpd;
            double ls;
            double tcl;
            double h;
            double td;
            try
            {
                td = Convert.ToDouble(data["td"]) * scale;
            }
            catch
            {
                td = Convert.ToDouble(data["tdz"]) * scale;
            }
            try
            {
                tcl = Convert.ToDouble(data["tcl"]) * scale;
            }
            catch
            {
                tcl = td * (4 / 12.0);
            }
            try
            {
                ls = Convert.ToDouble(data["ls"]) * scale;
            }
            catch
            {
                ls = oal * (20.0 / 46.0);
            }
            try
            {
                tcpd = Convert.ToDouble(data["tcpd"]) * scale;
            }
            catch
            {
                tcpd = td * (10 / 12.0);
            }
            
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.5 * (oal / 46.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            double drvsc = Convert.ToDouble(data["drvsc"]) * scale;
            double p = Convert.ToDouble(data["tp"]) * scale;//螺距
            if (p <= 8)
            {
                p = Convert.ToDouble(data["tp"]) * scale;//螺距
            }
            else
            {
                p = (25.4 / (Convert.ToDouble(data["tp"]) )) * scale;
            }
            try
            {
                h = Convert.ToDouble(data["h"]) * scale;
            }
            catch
            {
                h = 0.866025404 * p;//根据螺纹牙型标准中的p得知h牙高的值
            }
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = td - h * 2;
            }
            double k = Convert.ToDouble(data["k"]);//螺纹头部断开角度
            double k_ = k * pi / 180;
            double an = 0;
            double an_ = an * pi / 180;
            double l5 = 4;
            double ap = 0;
            double γp = 5;
            double ap_ = ap * pi / 180;
            double fha = 77;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;

            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, 0, oal + 5);
            Vector2 p0_2 = fun.Polar(p0, pi, 5);
            Vector2 p1 = fun.Polar(p0, pi / 2, (tcpd) / 15.0);
            Vector2 p2 = fun.Polar(p0, pi / -2, tcpd / 15.0);
            Vector2 p3 = fun.Polar(p2, 0, thl);
            Vector2 p4 = fun.Polar(p1, 0, thl);
            Vector2 p5_1 = fun.Polar(p0, pi / 2, (tcpd) / 2.0);
            Vector2 p5_2 = fun.Polar(p5_1, k_ , oal);
            Vector2 p5 = p0;
            Vector2 p6 = p0;
            Vector2 p7 = p0;
            Vector2 p8;
            Vector2 p9;
            Vector2 p10;
            Vector2 p11;
            Vector2 p12;
            Vector2 p13;
            Vector2 p16 = p0;
            var polyline3 = Pus.AddPointsToLwPolyLine(p4, p1, p2, p3);
            //dxf.AddEntity(polyline3);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            for (int i = 0; i < tcl / p; i++)
            {

                if (i == 0)
                {
                    p5 = fun.Polar(p0, pi / 2, (tcpd) / 2.0);
                    p6 = new Vector2(p / 2.0, p5.Y + h);
                    p7 = new Vector2(p, p5.Y);
                    Vector2 p8_1 = fun.Polar(p7, pi + fha_, oal);
                    p8 = fun.Inters(p1, p4, p7, p8_1);
                    Vector2 p9_0 = fun.Polar(p5, 10 * pi / 180, oal);
                    p9 = fun.Inters(p6, p7, p5, p9_0);
                    p10 = fun.Inters(p5, p6, p5, p9_0);
                    p11 = fun.mirrorpoint(p5, p0_1, p0_2);
                    p12 = fun.Inters(p2, p3, p7, p8_1);
                    p13 = fun.Inters(p2, p11, p7, p8_1);
                    var polyline1 = Pus.AddPointsToLwPolyLine(p1, p5, p10, p9, p7, p8);
                    var polyline2 = Pus.AddPointsToLwPolyLine(p2, p11, p13, p12);
                    //dxf.AddEntity(new EntityObject[] { polyline2, polyline1 });
                    fun.PolyFill(dxf, polyline1, 0.5, contour);
                    fun.PolyFill(dxf, polyline2, 0.5, contour);
                }
                else if (i == 1)
                {
                    p5 = new Vector2((i) * p, tcpd / 2.0);
                    p6 = new Vector2(p / 2.0 + ((i) * p), p5.Y + h);
                    p7 = new Vector2(p + (p * i), p5.Y);
                    Vector2 p8_1 = fun.Polar(p7, pi + fha_, oal);
                    p8 = fun.Inters(p1, p4, p7, p8_1);
                    Vector2 p9_0 = fun.Polar(p5, 10 * pi / 180, oal);
                    p9 = fun.Inters(p6, p7, p5_1, p5_2);
                    p10 = fun.Inters(p5, p6, p5_1, p5_2);
                    Vector2 p11_0 = fun.Polar(p7, fun.CalAngle(p7, p8), oal);
                    p11 = new Vector2(0, -tcpd / 2.0);
                    p12 = fun.Inters(p2, p3, p7, p8_1);
                    Vector2 p13_0 = fun.Polar(p11, pi / 2, h);
                    p13 = fun.Polar(p12, pi + fha_, fun.CalDistance(p8, p7) + h / 2.0);
                    var polyline1 = Pus.AddPointsToLwPolyLine(p5, p10, p9, p7, p8);
                    var polyline2 = Pus.AddPointsToLwPolyLine(p11, p13, p12);
                    //dxf.AddEntity(new EntityObject[] { polyline2, polyline1 });
                    fun.PolyFill(dxf, polyline1, 0.5, contour);
                    fun.PolyFill(dxf, polyline2, 0.5, contour);
                }
                else
                {
                    p5 = new Vector2((i) * p, tcpd / 2.0);
                    p6 = new Vector2(p / 2.0 + ((i) * p), p5.Y + h);
                    p7 = new Vector2(p + (p * i), p5.Y);
                    Vector2 p8_1 = fun.Polar(p7, pi + fha_, oal);
                    p8 = fun.Inters(p1, p4, p7, p8_1);
                    Vector2 p9_0 = fun.Polar(p5, 10 * pi / 180, oal);
                    p9 = fun.Inters(p6, p7, p5_1, p5_2);
                    p10 = fun.Inters(p5, p6, p5_1, p5_2);
                    Vector2 p11_0 = fun.Polar(p5, fun.CalAngle(p7, p8_1), oal);
                    p11 = fun.Inters(p5, p11_0, p2, p3);
                    p12 = fun.Inters(p7, p8_1, p2, p3);
                    Vector2 p14_0 = fun.Polar(p10, pi + fha_, oal);
                    Vector2 p14_1 = fun.Inters(p10, p14_0, p1, p4);
                    Vector2 p14_2 = fun.Inters(p10, p14_0, p2, p3);
                    Vector2 p15_0 = fun.Polar(p9, pi + fha_, oal);
                    Vector2 p15_1 = fun.Inters(p15_0, p9, p1, p4);
                    Vector2 p15_2 = fun.Inters(p15_0, p9, p2, p3);
                    Vector2 p13_0 = fun.Polar(p5, fha_ + pi, oal);
                    Vector2 p13_1 = fun.Inters(p5, p13_0, p1, p4);
                    Vector2 p13_2 = fun.Inters(p2, p3, p5, p13_0);
                    p13 = fun.Polar(p11, pi + fha_, fun.CalDistance(p13_1, p5));
                    Vector2 p14 = fun.Polar(p13, -fun.CalAngle(p5, p10), fun.CalDistance(p5, p10));
                    Vector2 p15 = fun.Polar(p14, -fun.CalAngle(p10, p9), fun.CalDistance(p10, p9));
                    p16 = fun.Polar(p15, -fun.CalAngle(p9, p7), fun.CalDistance(p9, p7));
                    var polyline1 = Pus.AddPointsToLwPolyLine(p5, p10, p9, p7, p8);
                    var polyline2 = Pus.AddPointsToLwPolyLine(p11, p13, p14, p15, p16, p12);
                    //dxf.AddEntity(new EntityObject[] { polyline1, polyline2  });
                    fun.PolyFill(dxf, polyline1, 0.5, contour);
                    fun.PolyFill(dxf, polyline2, 0.5, contour);
                }
            }
            Vector2 p17 = p7;
            Vector2 p18 = p0;
            Vector2 p19 = p0;
            Vector2 p26 = p0;
            for (int j = 0; j < (thl - tcl) / p; j++)
            {
                p18 = fun.Polar(p17, fun.CalAngle(p5, p6), fun.CalDistance(p5, p6));
                p19 = fun.Polar(p18, -fun.CalAngle(p17, p18), fun.CalDistance(p17, p18));
                Vector2 p20_0 = fun.Polar(p17, fha_ + pi, oal);
                Vector2 p20 = fun.Inters(p20_0, p17, p1, p4);
                Vector2 p21_0 = fun.Polar(p19, fha_ + pi, oal);
                Vector2 p21 = fun.Inters(p19, p21_0, p1, p4);
                Vector2 p22 = fun.Inters(p17, p20_0, p2, p3);
                Vector2 p23 = fun.Inters(p19, p21_0, p2, p3);
                Vector2 p24 = fun.Polar(p22, fha_ + pi, fun.CalDistance(p20, p17));
                Vector2 p25_0 = fun.Polar(p18, fha_ + pi, oal);
                Vector2 p25_1 = fun.Inters(p18, p25_0, p1, p4);
                Vector2 p25_2 = fun.Inters(p18, p25_0, p2, p3);
                Vector2 p25 = fun.Polar(p25_2, fha_ + pi, fun.CalDistance(p18, p25_1));
                p26 = fun.Polar(p23, fha_ + pi, fun.CalDistance(p19, p21));
                var polyline4 = Pus.AddPointsToLwPolyLine(p17, p18, p19, p21);
                var polyline5 = Pus.AddPointsToLwPolyLine(p22, p24, p25, p26, p23);

                //dxf.AddEntity(new EntityObject[] { polyline4,polyline5  });
                p17 = p19;
                fun.PolyFill(dxf, polyline5, 0.5, contour);
                fun.PolyFill(dxf, polyline4, 0.5, contour);
            }
            Vector2 p27_0 = fun.Polar(p19, pi / -2, oal);
            Vector2 p27_1 = fun.Inters(p19, p27_0, p1, p4);
            Vector2 p27_2 = fun.Inters(p19, p27_0, p2, p3);
            Vector2 p27 = fun.Polar(p27_2, pi / -2, fun.CalDistance(p19, p27_1));
            Vector2 p28 = new Vector2(p27.X - p / 2.0, p27.Y - h);
            Vector2 p29 = fun.Polar(p0, 0, thl + thl * (6.0 / 80.0));
            var polyline6 = Pus.AddPointsToLwPolyLine(p19, p27_1, p4, p29, p3, p27_2, p27, p28, p26);
            polyline6.Vertexes[2].Bulge = -Math.Tan(pi / 4 / 4);
            polyline6.Vertexes[3].Bulge = -Math.Tan(pi / 4 / 4);

            Vector2 p30 = fun.Polar(p27_2, pi / 2, fun.CalDistance(p27_1, p27_2) / 2.0);
            Vector2 p31 = fun.Polar(p0, 0, oal);
            Vector2 p32 = fun.Polar(p31, pi / 2, dmm / 2.0);
            Vector2 p33 = fun.Polar(p31, pi / -2, dmm / 2.0);
            Vector2 p34 = fun.Polar(p32, pi, ls);
            Vector2 p35 = fun.mirrorpoint(p34, p0_1, p0_2);
            Vector2 p36 = new Vector2(p34.X, dn / 2);
            Vector2 p37 = new Vector2(p35.X, dn / -2);
            Vector2 p38 = fun.Polar(p37, pi, oal - (ls + thl) - Math.Abs ( (p19.Y - p36.Y))*2);
            
            Vector2 p39 = fun.mirrorpoint(p38, p0_1, p0_2);
            Vector2 p40 = fun.Polar(p32, pi, drvl);
            Vector2 p41 = new Vector2(p40.X, dmm / 20.0);
            Vector2 p42 = new Vector2(p31.X, dmm / 20.0);
            Vector2 p43 = fun.mirrorpoint(p42, p0_1, p0_2);
            Vector2 p44 = fun.mirrorpoint(p41, p0_1, p0_2);
            Vector2 p45 = fun.mirrorpoint(p40, p0_1, p0_2);
            var polyline7 = Pus.AddPointsToLwPolyLine(p19, p39, p36, p37, p36, p34, p32, p33, p35, p37, p38, p27);
            if (p19.Y - p36.Y > 0)
            {
                polyline7.Vertexes[0].Bulge = Math.Tan(pi / 2 / 4);
                polyline7.Vertexes[10].Bulge = Math.Tan(pi / 2 / 4);
            }
            else
            {
                polyline7.Vertexes[0].Bulge = -Math.Tan(pi / 2 / 4);
                polyline7.Vertexes[10].Bulge = -Math.Tan(pi / 2 / 4);
            }
            var polyline8 = Pus.AddPointsToLwPolyLine(p32, p41, p42, p41, p40, p42, p43, p45, p44, p43, p44, p33);
            //dxf.AddEntity(new EntityObject[] { polyline6, polyline7, polyline8 });
            fun.PolyFill(dxf, polyline6, 0.5, contour);
            fun.PolyFill(dxf, polyline7, 0.5, contour);
            fun.PolyFill(dxf, polyline8, 0.5, contour);

            Vector2 p46 = fun.Polar(p0, pi, td * 8.5);
            Vector2 p46_1 = fun.Polar(p46, pi, td / 2.0 + 5);
            Vector2 p46_2 = fun.Polar(p46, 0, td / 2.0 + 5);
            Vector2 p46_3 = fun.Polar(p46, pi / 2, td / 2.0 + 5);
            Vector2 p46_4 = fun.Polar(p46, pi / -2, td / 2.0 + 5);
            Vector2 p47 = fun.Polar(p46, pi / 2, td / 2.0);
            Vector2 p48 = fun.Polar(p46, pi / -2, td / 2.0);
            Vector2 p49 = fun.Polar(p46, 0, td / 2.0);
            Vector2 p50 = fun.Polar(p46, pi, td / 2.0);
            var polyline9 = Pus.AddPointsToLwPolyLine(p49, p47, p50, p48, p49);
            polyline9.Vertexes[0].Bulge = Math.Tan((pi / 2-7*pi/180) / 4);
            polyline9.Vertexes[1].Bulge = Math.Tan((pi / 2-7*pi/180) / 4);
            polyline9.Vertexes[2].Bulge = Math.Tan((pi / 2-7*pi/180) / 4);
            polyline9.Vertexes[3].Bulge = Math.Tan((pi / 2-7*pi/180) / 4);
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = polyline9.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = polyline9.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)polyline9.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)polyline9.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 3 * (oal / 40.0), hline1, harc1, hatching);
            //dxf.AddEntity(polyline9);
            fun.PolyFill(dxf, polyline9, 0.5, contour);
            Circle circle1 = new Circle(p46, td / 2.0);
            circle1.Linetype = Linetype.Dashed   ;
            circle1.Lineweight = Lineweight.W35;
            circle1.Layer = refin;
            dxf.AddEntity(circle1);
            Line line1 = new Line(p0_1, p0_2);
            line1.Linetype = Linetype.DashDot;
            line1.Lineweight = Lineweight.W25;
            line1.Layer = centre;
            dxf.AddEntity(line1);
            Line line2 = new Line(p46_1, p46_2);
            line2.Linetype = Linetype.DashDot;
            line2.Lineweight = Lineweight.W25;
            line2.Layer = centre;
            dxf.AddEntity(line2);
            Line line3 = new Line(p46_3, p46_4);
            line3.Linetype = Linetype.DashDot;
            line3.Lineweight = Lineweight.W25;
            line3.Layer = centre;
            dxf.AddEntity(line3);


            Vector2 p51 = fun.Polar(p0, 0, (oal + td * 5));
            Vector2 p52 = fun.Polar(p51, pi / 2, dmm / 2.0);
            Vector2 p53 = fun.Polar(p51, pi / -2, dmm/2.0);
            Vector2 p54 = fun.Polar(p51, pi, dmm / 2.0);
            Vector2 p55 = fun.Polar(p51, 0, dmm / 2.0);
            Vector2 p52_1 = fun.Polar(p52, -pi / 4, fun.CalDistance(p52, p54) / 10.0);
            Vector2 p52_2 = fun.Polar(p52, pi + pi / 4, fun.CalDistance(p52, p54) / 10.0);
            Vector2 p54_1 = fun.Polar(p54, pi / 4, fun.CalDistance(p52, p54) / 10.0);
            Vector2 p54_2 = fun.Polar(p54, pi / -4, fun.CalDistance(p52, p54) / 10.0);
            Vector2 p53_1 = fun.Polar(p53, pi - pi / 4, fun.CalDistance(p52, p54) / 10.0);
            Vector2 p53_2 = fun.Polar(p53, pi / 4, fun.CalDistance(p52, p54) / 10.0);
            Vector2 p55_1 = fun.Polar(p55, pi + pi / 4, fun.CalDistance(p52, p54) / 10.0);
            Vector2 p55_2 = fun.Polar(p55, pi - pi / 4, fun.CalDistance(p52, p54) / 10.0);
            var polyline10 = Pus.AddPointsToLwPolyLine(p52_1, p52_2, p54_1, p54_2, p53_1, p53_2, p55_1, p55_2,p52_1 );
            polyline10.Vertexes[0].Bulge = Math.Tan((pi / 2 ) / 4);
            polyline10.Vertexes[2].Bulge = Math.Tan((pi / 2 ) / 4);
            polyline10.Vertexes[4].Bulge = Math.Tan((pi / 2 ) / 4);
            polyline10.Vertexes[6].Bulge = Math.Tan((pi / 2 ) / 4);
            htype1 = new String[100];
            hline1 = new Line[100];
            harc1 = new Arc[100];
            hnumst1 = polyline10.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = polyline10.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)polyline10.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)polyline10.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 3 * (oal / 40.0), hline1, harc1, hatching);
            //dxf.AddEntity(polyline10);
            fun.PolyFill(dxf, polyline10, 0.5, contour);
            //标注
            double offset = 7.5 * (oal / 46.0);
            scale = oal / 46.0;
            Vector2 v1 = fun.Polar(p37, pi / 2, fun.CalDistance(p36, p37) / 2.0);
            Vector2 v2 = fun.Polar(p27_1, pi / 2, tcpd / 2.0 - tcpd / 15.0);
            Vector2 v3 = fun.Polar(p0, pi / 2, tcpd / 2.0);
            Vector2 v4 = fun.Polar(p0, pi / -2, tcpd / 2.0);
            Vector2 v5 = new Vector2(tcl, td / 2.0);
            Vector2 v6 = new Vector2(tcl, td / -2.0);
            Vector2 v7 = fun.Polar(p28, pi, p);
            Vector2 v8 = fun.Polar(p28, pi, td * Math.Tan(pi / 2 - fha_));
            Vector2 v9 = fun.Polar(p31, pi, drvl);
            Vector2 v10 = fun.Polar(p46, pi / 4, td / 2.0);
            Vector2 v11 = fun.Polar(p46, pi / 4, td / 2.0 - td / 60.0);
            if (dim == 0)
            {
                fun.dimrot1(dxf, p0, p31, 0, offset * 2, 1, 1.2 * scale, 1.6 * scale, 0, "OAL", "", "");
                fun.dimrot1(dxf, p0, v2, 0, offset * 1.5 - (v2.Y) / 2.0, 1, 1.2 * scale, 1.6 * scale, 0, "THL", "", "");
                fun.dimrot1(dxf, v3, v4, 90, offset, 1, 1.2 * scale, 1.6 * scale, 0, "TCPD", "", "");
                fun.dimrot1(dxf, v5, v6, 90, offset * 2.3, 1, 1.2 * scale, 1.6 * scale, 0, "TD", "", "");
                fun.dimrot1(dxf, p32, p33, -90, offset, 1, 1.2 * scale, 1.6 * scale, 0, "DCONMS", "", "");
                fun.dimrot1(dxf, v4, v6, 180, offset, 1, 1.2 * scale, 1.6 * scale, 0, "TCL", "", "");
                fun.dimrot1(dxf, p28, v8, 180, offset, 1, 1.2 * scale, 1.6 * scale, 0, "TP", "", "");
                fun.dimrot1(dxf, v10, v11, 45, offset, 1, 1.2 * scale, 1.6 * scale, 0, "K", "", "");
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]) * scale;
                    fun.dimrot1(dxf, p31, v9, 180, offset * 2, 1, 1.2 * scale, 1.6 * scale, 0, "DRVL", "", "");
                }
                catch
                {}
                try
                {
                    a = Convert.ToDouble(data["dconms"]) * scale;
                    fun.dimrot1(dxf, p52, p55, -45, offset, 1, 1.2 * scale, 1.6 * scale, 0, "α", "", "");
                }
                catch
                { }
                try
                {
                    ls = Convert.ToDouble(data["LS"]) * scale;
                    fun.dimrot1(dxf, p31, v1, 0, offset * 1.5, 1, 1.2 * scale, 1.6 * scale, 0, "LS", "", "");
                }
                catch
                { }
            }
            else
            {
                scale = 5;
                fun.dimrot1(dxf, p0, p31, 0, offset * 2, 1, 1.2 * scale, 1.6 * scale, 0, "OAL="+oal/scale , "", "");
                fun.dimrot1(dxf, p0, v2, 0, offset * 1.5 - (v2.Y) / 2.0, 1, 1.2 * scale, 1.6 * scale, 0, "THL="+thl/scale  , "", "");
                fun.dimrot1(dxf, v3, v4, 90, offset, 1, 1.2 * scale, 1.6 * scale, 0, "TCPD="+tcpd/scale  , "", "");
                fun.dimrot1(dxf, v5, v6, 90, offset * 2.3, 1, 1.2 * scale, 1.6 * scale, 0, "TD="+td / scale, "", "");
                fun.dimrot1(dxf, p32, p33, -90, offset, 1, 1.2 * scale, 1.6 * scale, 0, "DCONMS="+dmm / scale, "", "");
                fun.dimrot1(dxf, v4, v6, 180, offset, 1, 1.2 * scale, 1.6 * scale, 0, "TCL="+tcl / scale, "", "");
                fun.dimrot1(dxf, p28, v8, 180, offset, 1, 1.2 * scale, 1.6 * scale, 0, "TP="+p / scale, "", "");
                fun.dimrot1(dxf, v10, v11, 45, offset, 1, 1.2 * scale, 1.6 * scale, 0, "K", "", "");
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]) * scale;
                    fun.dimrot1(dxf, p31, v9, 180, offset * 2, 1, 1.2 * scale, 1.6 * scale, 0, "DRVL="+drvl / scale, "", "");
                }
                catch
                { }
                try
                {
                    ls = Convert.ToDouble(data["LS"]) * scale;
                    fun.dimrot1(dxf, p31, v1, 0, offset * 1.5, 1, 1.2 * scale, 1.6 * scale, 0, "LS="+ls / scale, "", "");
                }
                catch
                { }
                try
                {
                    a = Convert.ToDouble(data["dconms"]) * scale;
                    fun.dimrot1(dxf, p52, p55, -45, offset, 1, 1.2 * scale, 1.6 * scale, 0, "α="+dmm / scale, "", "");
                }
                catch
                { }
            }

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }






            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void spiralflute(Dictionary<string, Object> data)//螺旋槽丝锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            refin.Linetype = Linetype.Dashed;
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            centre.Linetype = Linetype.DashDot;
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double dim = 0;
            double scale = 5;
            /*double tcl = 4 * scale;
            double td = 10 * scale;
            double a = 10 * scale;
            double tg = 1.5;
            double tg_ = tg * pi / 180;
            double thl = 30 * scale;
            double ls = 20 * scale;
            double oal = 120 * scale;
            double dmm = 8 * scale;
            double dn;
            double drvl;
            double lu;
            double drvsc;
           
            try
            {
                ls = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                ls = oal * (20.0 / 46.0);
            }
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.5 * (oal / 46.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            try
            {
                drvsc = Convert.ToDouble(data["drvsc"]) * scale;
            }
            catch
            {
                drvsc = dmm;
            }
            
            double p = 1*scale  ;//螺距
            double h = 0.866025404 * p;//根据螺纹牙型标准中的p得知h牙高的值
           try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = td -h*2;
            }
            double fha = 83;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;*/
            double tcl = Convert.ToDouble(data["tcl"]) * scale;
            double td = Convert.ToDouble(data["td"]) * scale;
            double tg = 1.5;
            double tg_ = tg * pi / 180;
            double thl = Convert.ToDouble(data["thl"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double dmm = Convert.ToDouble(data["dconms"]) * scale;
            double dn;
            double drvl;
            double lu;
            double drvsc;
            double ls;
          
            try
            {
                ls = Convert.ToDouble(data["ls"]) * scale;
            }
            catch
            {
                ls = oal * (20.0 / 46.0);
            }
            try
            {
                drvl = Convert.ToDouble(data["drvl"]) * scale;
            }
            catch
            {
                drvl = 3.5 * (oal / 46.0);
            }
            try
            {
                lu = Convert.ToDouble(data["lu"]) * scale;
            }
            catch
            {
                lu = oal * (26 / 40.0);
            }
            try
            {
                drvsc = Convert.ToDouble(data["drvsc"]) * scale;
            }
            catch
            {
                drvsc = dmm;
            }
            double p = Convert.ToDouble(data["tp"]) * scale;//螺距
            double h = 0.866025404 * p;//根据螺纹牙型标准中的p得知h牙高的值
            try
            {
                dn = Convert.ToDouble(data["dn"]) * scale;
            }
            catch
            {
                dn = td -h*2;
            }
            double fha = 83;//定值，螺纹线偏角，看情况改
            double fha_ = fha * pi / 180;
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, 5);
            Vector2 p0_2 = fun.Polar(p0, 0, oal + 5);
            Vector2 p1 = fun.Polar(p0, 0, thl);
            Vector2 p2 = fun.Polar(p1, pi / 2, td / 2.0);
            Vector2 p3 = fun.Polar(p1, pi / -2, td / 2.0);
            Vector2 p4_1 = fun.Polar(p0, pi / -2, oal);
            Vector2 p5_1 = fun.Polar(p0, pi / 2, oal);
            Vector2 p4_2 = fun.Polar(p3, pi - tg_, oal);
            Vector2 p5_2 = fun.Polar(p2, pi + tg_, oal);
            Vector2 p4 = fun.Inters(p0, p4_1, p3, p4_2);
            Vector2 p5 = fun.Inters(p0, p5_1, p2, p5_2);
            Vector2 p2_0 = fun.Polar(p2, pi / 2, 0.1);
            Vector2 p3_0 = fun.Polar(p3, pi / -2, 0.1);
            Vector2 p4_0 = fun.Polar(p4, pi / -2, 0.1);
            Vector2 p5_0 = fun.Polar(p5, pi / 2, 0.1);
            var polyline2 = Pus.AddPointsToLwPolyLine(p2_0, p5_0, p4_0, p3_0);
            Vector2 p6_0 = fun.Polar(p4, 0, tcl);
            Vector2 p6_1 = fun.Polar(p6_0, pi / -2, oal / 2.0);
            Vector2 p6_2 = fun.Polar(p6_0, pi / 2, oal / 2.0);
            Vector2 p6 = fun.Inters(p4, p3, p6_1, p6_2);
            Vector2 p7 = fun.Inters(p5, p2, p6_1, p6_2);
            Vector2 p8 = fun.Polar(p5, pi / -2, fun.CalDistance(p0, p5) / 3.0);
            Vector2 p9 = fun.Polar(p4, pi / 2, fun.CalDistance(p0, p5) * (2 / 3.0));
            Vector2 p10_0 = fun.Polar(p9, tg_, oal);
            Vector2 p10 = fun.Inters(p6, p7, p9, p10_0);
            Vector2 p11_0 = fun.Polar(p8, tg_, oal);
            Vector2 p11 = fun.Inters(p8, p11_0, p6, p7);
            var polyline1 = Pus.AddPointsToLwPolyLine(p8, p11, p7, p5, p4, p6, p10, p9);
            Vector2 p12 = fun.Polar(p1, 0, thl/ 20.0);
            Vector2 p13 = fun.Polar(p12, pi / 2, dn / 2.0);
            Vector2 p14 = fun.Polar(p12, pi / -2, dn / 2.0);
            Vector2 p15 = fun.Polar(p2, pi / -2, fun.CalDistance(p6, p10));
            Vector2 p16 = fun.Polar(p3, pi / 2, fun.CalDistance(p7, p11));
            Vector2 p16_1 = fun.Polar(p2, pi / -2, 0.1 );
            Vector2 p16_2 = fun.Polar(p6, pi / 2, 0.1);
            Vector2 p17_0 = fun.Polar(p0, 0, thl * (4 / 5.0));
            Vector2 p17_1 = fun.Polar(p17_0, pi / 2, oal / 2.0);
            Vector2 p17_2 = fun.Polar(p17_0, pi / -2, oal / 2.0);
            Vector2 p18_0 = fun.Polar(p0, 0, thl / 3.0);
            Vector2 p18_1 = fun.Polar(p18_0, pi / 2, oal / 2.0);
            Vector2 p18_2 = fun.Polar(p18_0, pi / -2, oal / 2.0);
            Arc arc2 = fun.DrawArc5(p16_1, new Line(p5, p2), p10);
            Arc arc3 = fun.DrawArc5(p16_2, new Line(p6, p3), p15);
            Vector2 p17 = fun.Inters1(p17_1, p17_2, arc2, 1);
            Vector2 p18 = fun.Inters1(p18_1, p18_2, arc3, 0);
            Vector2 p19_0 = fun.Polar(p7, pi / -2, 0.1);
            Vector2 p20_0 = fun.Polar(p3, pi / 2, 0.1);
            Arc arc4 = fun.DrawArc5(p17, new Line(p5, p2), p11);
            var polyline3 = Pus.AddPointsToLwPolyLine(p15, p2, p13, p14, p3, p16);
            Arc arc1 = fun.DrawArc5(p16, new Line(p13, p14), p15);
            Arc arc5 = fun.DrawArc5(p18, new Line(p6, p3), p16);
            Arc arc6 = fun.DrawArc5(p17, new Line(p5, p2), p19_0);
            Arc arc7 = fun.DrawArc5(p18, new Line(p4, p14), p3);
            //dxf.AddEntity(new EntityObject[] {polyline1 , polyline3, arc1 });
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            fun.drawBArc(dxf, arc1, 0.5, contour);
            Vector2 p19 = Pus.ToV2(arc4.Center);
            double ang1 = fun.CalAngle(p19, p17);
            double ang2 = fun.CalAngle(p19, p11);
            double ang3 = (ang2 - ang1) ;
            double arc4d = (arc4.Radius * 2 * pi)*(ang3/(2*pi));//arc4的周长
            Vector2 p20;
            Vector2 p21;
            Vector2 p22;
            Vector2 p23;
            Vector2 p24;
            for (int i = 0; i < arc4d / p-1; i++)
            {
                Vector2 p20_1 = fun.Polar(p11, 0, p);
                Vector2 p20_2 = fun.Polar(p11, -89*pi/180, p);
                Arc arc8 = fun.DrawArc(p20_1, p11, p20_2);
                p20 = fun.Inters4(arc8, arc4, 0);
                Vector2 p21_0 = fun.Polar(p11, fun.CalAngle(p11, p20), fun.CalDistance(p11, p20) / 2.0);
                p21 = fun.Polar(p21_0, fun.CalAngle(p11, p20) + pi / 2, h);
                Vector2 p22_0 = fun.Polar(p11, fun.CalAngle(p21_0, p21), thl);
                Vector2 p24_0 = fun.Polar(p20, fun.CalAngle(p21_0, p21), thl);
                if (i*p < ((arc4d) / p - 1)*p/1.5)
                {
                    p22 = fun.Inters1(p11, p22_0, arc6, 0);
                    p23 = fun.Polar(p22, fun.CalAngle(p11, p21), fun.CalDistance(p11, p21));
                    p24 = fun.Inters1(p20, p24_0, arc6, 0);
                }
                else
                {
                    p22 = p11;
                    p23 = p21;
                    p24 = p20;
                }
                var polyline4 = Pus.AddPointsToLwPolyLine(p11, p21,p23,p21, p20, p24, p23, p22, p11);
               if (i == 0)
                {
                    var polyline5 = Pus.AddPointsToLwPolyLine(p20, p24, p7, p11, p20);
                    //dxf.AddEntity(polyline5);
                    fun.PolyFill(dxf, polyline5, 0.5, contour);
                }
               else
               {
                    //dxf.AddEntity(polyline4);
                    fun.PolyFill(dxf, polyline4, 0.5, contour);
                }
                p11 = p20;
            }

            Vector2 p25 = Pus.ToV2(arc2.Center);
            double ang4 = fun.CalAngle(p25, p16_1);
            double ang5 = fun.CalAngle(p25, p10);
            double ang6 = (ang5 - ang4);
            double arc2d=(arc2.Radius * 2 * pi) * (ang6 / (2 * pi));
            Vector2 p26;
            Vector2 p27;
            for (int i = 0; i < arc2d / p; i++)
            {
               
                    Vector2 p20_1 = fun.Polar(p10, 89 * pi / 180, p);
                    Vector2 p20_2 = fun.Polar(p10, -89 * pi / 180, p);
                    Arc arc8 = fun.DrawArc(p20_1, p10, p20_2);
                    p26 = fun.Inters4(arc8, arc2, 0);
                    Vector2 p21_0 = fun.Polar(p10, fun.CalAngle(p10, p26), fun.CalDistance(p10, p26) / 2.0);
                    p21 = fun.Polar(p21_0, fun.CalAngle(p10, p26) + pi / 2, h);
                    Vector2 p21_1 = fun.Polar(p6, 89 * pi / 180, p);
                    Vector2 p21_2 = fun.Polar(p6, -89 * pi / 180, p);
                    Arc arc9 = fun.DrawArc(p21_2, p6, p21_1);
                    p27 = fun.Inters4(arc9, arc3, 1);
                    Vector2 p22_0 = fun.Polar(p6, fun.CalAngle(p6, p27), fun.CalDistance(p6, p27) / 2.0);
                    p22 = fun.Polar(p22_0, fun.CalAngle(p6, p27) + pi / 2, h);
                    var polyline4 = Pus.AddPointsToLwPolyLine(p6, p22, p21, p22, p27, p26, p21, p10, p6);
                    if (i < arc2d / p-1)
                    {
                        polyline4 = Pus.AddPointsToLwPolyLine(p6, p22, p21, p22, p27, p26, p21, p10, p6);
                    }
                    else
                    {
                    polyline4 = Pus.AddPointsToLwPolyLine(p10, p2, p15, p6);
                    }
                    //dxf.AddEntity(polyline4);
                fun.PolyFill(dxf, polyline4, 0.5, contour);
                p6 = p27;
                    p10 = p26;
               
            }



            Vector2 p28 = Pus.ToV2(arc4.Center);
            double ang7 = fun.CalAngle(p19, p17);
            double ang8 = fun.CalAngle(p19, p11);
            double ang9 = (ang2 - ang1);
            double arc5d = (arc5.Radius * 2 * pi) * (ang9 / (2 * pi));//arc4的周长

            for (int i = 0; i < arc4d / p ; i++)
            {
                Vector2 p20_1 = fun.Polar(p16, pi-89*pi/180, p);
                Vector2 p20_2 = fun.Polar(p16,pi+89 * pi / 180, p);
                Arc arc8 = fun.DrawArc(p20_1, p16, p20_2);
                p20 = fun.Inters4(arc8, arc5, 0);
                Vector2 p21_0 = fun.Polar(p16, fun.CalAngle(p16, p20), fun.CalDistance(p16, p20) / 2.0);
                p21 = fun.Polar(p21_0, fun.CalAngle(p16, p20) + pi / 2, h);
                Vector2 p22_0 = fun.Polar(p16, fun.CalAngle(p21_0, p21), thl);
                Vector2 p24_0 = fun.Polar(p20, fun.CalAngle(p21_0, p21), thl);
                if (i * p < ((arc5d) / p - 1) * p / 3)
                {
                    p22 = fun.Inters1(p16, p22_0, arc7, 1);
                    p23 = fun.Polar(p22, fun.CalAngle(p16, p21), fun.CalDistance(p16, p21));
                    p24 = fun.Inters1(p20, p24_0, arc7, 1);
                }
                else
                {
                    p22 = p16;
                    p23 = p21;
                    p24 = p20;
                }
                var polyline4 = Pus.AddPointsToLwPolyLine(p16, p21, p23, p21, p20, p24, p23, p22, p16);
                if (i == 0)
                {
                    var polyline5 = Pus.AddPointsToLwPolyLine(p20, p24, p3, p16, p20);
                   // dxf.AddEntity(polyline5);
                    fun.PolyFill(dxf, polyline5, 0.5, contour);
                }
                else
                {
                    //dxf.AddEntity(polyline4);
                    fun.PolyFill(dxf, polyline4, 0.5, contour);
                }
                p16 = p20;
            }
            Vector2 p29 = new Vector2(oal, 0);
            Vector2 p30 = fun.Polar(p29, pi / 2, dmm / 2.0);
            Vector2 p31 = fun.Polar(p30, pi, ls);
            Vector2 p32_1 = fun.Polar(p13, pi , oal);
            Vector2 p32_2;
            Vector2 p32;
            if (dmm > dn)
            {
                p32_2 = fun.Polar(p31, pi + pi / 4, oal);
                p32 = fun.Inters(p31, p32_2, p13, p32_1);
            }
            else if (dmm == dn)
            {
                p32 = p31 ;

            }
            else
            {
                p32_2 = fun.Polar(p31, pi - pi / 4, oal);
                p32 = fun.Inters(p31, p32_2, p13, p32_1);
            }
            
            Vector2 p33 = fun.mirrorpoint(p32, p0_1, p0_2);
            Vector2 p34 = fun.mirrorpoint(p31, p0_1, p0_2);
            Vector2 p35 = fun.mirrorpoint(p30, p0_1, p0_2);
            var polyline6 = Pus.AddPointsToLwPolyLine(p13, p32, p33, p32, p31, p34, p31, p30, p35, p34, p33, p14);
            //dxf.AddEntity(polyline6);
            fun.PolyFill(dxf, polyline6, 0.5, contour);
            Vector2 p36 = fun.Polar(p35, pi, drvl );
            Vector2 p37 = fun.mirrorpoint(p36, p0_1, p0_2);
            Vector2 p38 = fun.Polar(p37, pi / -2, dmm/2.0 - dmm / 10.0);
            Vector2 p39 = fun.mirrorpoint(p38, p0_1, p0_2);
            Vector2 p40 = new Vector2(p30.X, p38.Y);
            Vector2 p41 = new Vector2(p30.X, p39.Y);
            var polyline7 = Pus.AddPointsToLwPolyLine(p30, p38, p40, p38, p37, p40, p41, p36, p39, p41, p39, p35);
            //dxf.AddEntity(polyline7);
            fun.PolyFill(dxf, polyline7, 0.5, contour);

            Vector2 p42 = fun.Polar(p0, pi, oal / 2.0);
            Circle cir1 = new Circle(p42, td / 2.0);
            Circle cir3 = new Circle(p42, td / 2.2);
            Circle cir2 = new Circle(p42, td / 5);
            Vector2 p43_1 = fun.Polar(p42, pi/2, cir1.Radius);
            Vector2 p43_2 = fun.Polar(p42, 40 * pi / 180, cir1.Radius);
            Vector2 p44_1 = fun.Polar(p42, pi / 2, cir3.Radius);
            Vector2 p44_2 = fun.Polar(p42, 40 * pi / 180, cir3.Radius);
            Arc arc10 = fun.DrawArc(p43_2, p42, p43_1);
            Arc arc11 = fun.DrawArc(p44_2, p42, p44_1);
            Vector2 p45=p0;
            Vector2 p48 = fun.Polar(p42, (125+120+120) * pi / 180 , cir2.Radius);

            
            for (int i = 1; i < 4; i++)
            {
                Vector2 p47 = fun.Polar(p42, 125*i * pi / 180 , cir2.Radius);
                Vector2 p45_1 = fun.rotatePoint_Changed(p42, p43_1, 120 * i);
                Vector2 p45_2 = fun.rotatePoint_Changed(p42, p43_2, 120 * i);
                Vector2 p46_1 = fun.rotatePoint_Changed(p42, p44_1, 120 * i);
                Vector2 p46_2 = fun.rotatePoint_Changed(p42, p44_2, 120 * i);
                Arc arc12 = fun.DrawArc(p45_2, p42, p45_1);
                Arc arc13 = fun.DrawArc(p46_2, p42, p46_1);
                Arc arc14;
                if (i == 1)
                {
                    arc14 = fun.DrawArc3(p45_2,p47, p43_1);
                    p45 = p45_1;
                }
                else if(i==2)
                {
                    arc14 = fun.DrawArc3(p45_2, p47, p45);
                    p45 = p45_1;
                }
                else
                {
                    //p47 = fun.Polar(p42, 125 * (i) * pi / 180, cir2.Radius);
                    arc14= fun.DrawArc3(p43_2, p47, p45);
                }
                //dxf.AddEntity(new EntityObject[] { arc12, arc13, arc14 });
                fun.drawBArc(dxf, arc13, 0.5, contour);
                fun.drawBArc(dxf, arc12, 0.5, contour);
                fun.drawBArc(dxf, arc14, 0.5, contour);
            }
            //dxf.AddEntity(new EntityObject[] { cir2, arc10, arc11 });
            fun.drawBArc(dxf, arc10, 0.5, contour);
            fun.drawBArc(dxf, arc11, 0.5, contour);
            cir2.Linetype = Linetype.DashDot ;
            cir2.Lineweight = Lineweight.W35;
            cir2.Layer = refin ;
            dxf.AddEntity(cir2);
            Vector2 p49 = fun.Polar(p0, 0, oal + oal / 3.0);
            Vector2 p50 = fun.Polar(p49, pi / 2, drvsc / 2.0);
            Vector2 p51 = fun.Polar(p49, 0, drvsc / 2.0);
            Vector2 p52 = fun.Polar(p49, pi / -2, drvsc / 2.0);
            Vector2 p53 = fun.Polar(p49, pi, drvsc / 2.0);
            Vector2 p50_1 = fun.Polar(p50, pi / -4, drvsc / 10.0);
            Vector2 p50_2 = fun.Polar(p50, pi + pi / 4, drvsc / 10.0);
            Vector2 p53_1 = fun.Polar(p53, pi / 4, drvsc / 10.0);
            Vector2 p53_2 = fun.Polar(p53, pi / -4, drvsc / 10.0);
            Vector2 p52_1 = fun.Polar(p52, pi - pi / 4, drvsc / 10.0);
            Vector2 p52_2 = fun.Polar(p52, pi / 4, drvsc / 10.0);
            Vector2 p51_1 = fun.Polar(p51, pi + pi / 4, drvsc / 10.0);
            Vector2 p51_2 = fun.Polar(p51, pi - pi / 4, drvsc / 10.0);

            Vector2 p49_1 = fun.Polar(p49, pi, drvsc/2.0+5);
            Vector2 p49_2 = fun.Polar(p49, 0, drvsc / 2.0 + 5);
            Vector2 p49_3 = fun.Polar(p49, pi/2, drvsc / 2.0 + 5);
            Vector2 p49_4 = fun.Polar(p49, pi/-2, drvsc / 2.0 + 5);
            Vector2 p42_1 = fun.Polar(p42, pi, drvsc / 2.0 + 5);
            Vector2 p42_2 = fun.Polar(p42, 0, drvsc / 2.0 + 5);
            Vector2 p42_3 = fun.Polar(p42, pi / 2, drvsc / 2.0 + 5);
            Vector2 p42_4 = fun.Polar(p42, pi / -2, drvsc / 2.0 + 5);


            Line line1 = new Line(p0_1, p0_2);
            line1.Linetype = Linetype.DashDot;
            line1.Lineweight = Lineweight.W35;
            line1.Layer = centre;
            dxf.AddEntity(line1);
            Line line2 = new Line(p49_1 , p49_2);
            line2.Linetype = Linetype.DashDot;
            line2.Lineweight = Lineweight.W35;
            line2.Layer = centre;
            dxf.AddEntity(line2);
            Line line3 = new Line(p49_4, p49_3);
            line3.Linetype = Linetype.DashDot;
            line3.Lineweight = Lineweight.W35;
            line3.Layer = centre;
            dxf.AddEntity(line3);
            Line line4 = new Line(p42_1, p42_2);
            line4.Linetype = Linetype.DashDot;
            line4.Lineweight = Lineweight.W35;
            line4.Layer = centre;
            dxf.AddEntity(line4);
            Line line5 = new Line(p42_4, p42_3);
            line5.Linetype = Linetype.DashDot;
            line5.Lineweight = Lineweight.W35;
            line5.Layer = centre;
            dxf.AddEntity(line5);
            var polyline9 = Pus.AddPointsToLwPolyLine(p50_1, p50_2, p53_1, p53_2, p52_1, p52_2, p51_1, p51_2,p50_1 );
             String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = polyline9.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = polyline9.Explode()[i].Type.ToString();    //将所有元素的类型记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)polyline9.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)polyline9.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 3 * (oal / 40.0), hline1, harc1, hatching);
            //dxf.AddEntity(polyline9);
            fun.PolyFill(dxf, polyline9, 0.5, contour);
            //标注
            if (dim == 0)
            {
                double offs = 10 * (oal / 60.0);
                double height = 1.2 * (oal / 60.0);
                double arrowsize = 1.6 * (oal / 60.0);
                double exline = 1 * (oal / 60.0);
                Vector2 v1 = fun.Polar(p0, pi / 2, td / 2 + h);
                Vector2 v2 = fun.Polar(v1, 0, thl / 2.0);
                Vector2 v3 = fun.mirrorpoint(v2, p0_1, p0_2);
                Vector2 v4 = fun.Polar(v3, 0, p/2.0);
                Vector2 v5 = fun.Polar(v4, 0, p );
                fun.dimrot1(dxf, p1, p0, 0, offs, 0.1, height, arrowsize, exline, "THL", "", "");
                fun.dimrot1(dxf, p29, p0, 0, offs*1.5, 0.1, height, arrowsize, exline, "OAL", "", "");
                fun.dimrot1(dxf, p4, p6, 180, offs*2, 0.1, height, arrowsize, exline, "TCL", "", "");
                fun.dimrot1(dxf, p30, p35, -90, offs, 0.1, height, arrowsize, exline, "DCONMS", "", "");
                fun.dimrot1(dxf, p5, p4, 90, offs, 0.1, height, arrowsize, exline, "TCPD", "", "");
                fun.dimrot1(dxf, v2, v3, 90, offs*2.5, 0.1, height, arrowsize, exline, "TD", "", "");
                fun.dimrot1(dxf, v5, v4, 180, offs, 0.1, height, arrowsize, exline, "TP", "", "");
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]) * scale;
                    fun.dimrot1(dxf, p35, p36, 180, offs, 0.1, height, arrowsize, exline, "DRVL", "", "");
                }
                catch
                { }
                try
                {
                    drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                    fun.dimrot1(dxf, p51_1, p51_2, -90, offs, 0.1, height, arrowsize, exline, "DRVSC", "", "");
                }
                catch
                { }
            }
            else
            {
                double offs = 10 * (oal / 60.0);
                double height = 1.2 * (oal / 60.0);
                double arrowsize = 1.6 * (oal / 60.0);
                double exline = 1 * (oal / 60.0);
                Vector2 v1 = fun.Polar(p0, pi / 2, td / 2 + h);
                Vector2 v2 = fun.Polar(v1, 0, thl / 2.0);
                Vector2 v3 = fun.mirrorpoint(v2, p0_1, p0_2);
                Vector2 v4 = fun.Polar(v3, 0, p / 2.0);
                Vector2 v5 = fun.Polar(v4, 0, p);
                fun.dimrot1(dxf, p1, p0, 0, offs, 0.1, height, arrowsize, exline, "THL="+thl/scale  , "", "");
                fun.dimrot1(dxf, p29, p0, 0, offs * 1.5, 0.1, height, arrowsize, exline, "OAL=" + thl/scale , "", "");
                fun.dimrot1(dxf, p4, p6, 180, offs * 2, 0.1, height, arrowsize, exline, "TCL=" + thl/scale , "", "");
                fun.dimrot1(dxf, p30, p35, -90, offs, 0.1, height, arrowsize, exline, "DCONMS=" + thl/scale , "", "");
                fun.dimrot1(dxf, p5, p4, 90, offs, 0.1, height, arrowsize, exline, "TCPD=" + thl/scale , "", "");
                fun.dimrot1(dxf, v2, v3, 90, offs * 2.5, 0.1, height, arrowsize, exline, "TD=" + thl/scale , "", "");
                fun.dimrot1(dxf, v5, v4, 180, offs, 0.1, height, arrowsize, exline, "TP=" + thl/scale , "", "");
                try
                {
                    drvl = Convert.ToDouble(data["drvl"]) * scale;
                    fun.dimrot1(dxf, p35, p36, 180, offs, 0.1, height, arrowsize, exline, "DRVL=" + thl/scale , "", "");
                }
                catch
                { }
                try
                {
                    drvsc = Convert.ToDouble(data["drvsc"]) * scale;
                    fun.dimrot1(dxf, p51_1, p51_2, -90, offs, 0.1, height, arrowsize, exline, "DRVSC="+drvsc/scale , "", "");
                }
                catch
                { }
            }


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
           
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
                dxf.Save(path);
            }
        }
    }